歡迎進入個案研究!

Python 工具箱

Hugo Bowne-Anderson

Data Scientist at DataCamp

世界銀行資料

  • 半世紀以上的全球經濟資料
  • 指標
    • 人口
    • 用電量
    • CO2 排放
    • 識字率
    • 失業率
    • 死亡率
Python 工具箱

使用 zip()

avengers = ['hawkeye', 'iron man', 'thor', 'quicksilver']
names = ['barton', 'stark', 'odinson', 'maximoff']

z = zip(avengers, names)
print(type(z))
<class 'zip'>
print(list(z))
[('hawkeye', 'barton'), ('iron man', 'stark'), 
('thor', 'odinson'), ('quicksilver', 'maximoff')]
Python 工具箱

定義函式

  • raise.py
def raise_both(value1, value2):
    """Raise value1 to the power of value2
    and vice versa."""
    new_value1 = value1 ** value2
    new_value2 = value2 ** value1
    new_tuple = (new_value1, new_value2)
    return new_tuple
Python 工具箱

複習:list comprehension

基礎

[output expression for iterator variable in iterable]

進階

[output expression + 
conditional on output for iterator variable in iterable +
conditional on iterable]
Python 工具箱

一起來練習吧!

Python 工具箱

Preparing Video For Download...