ケーススタディへようこそ!

Python Toolbox

Hugo Bowne-Anderson

Data Scientist at DataCamp

世界銀行データ

  • 半世紀以上にわたる世界経済のデータ
  • 指標
    • 人口
    • 電力消費量
    • CO2排出量
    • 識字率
    • 失業率
    • 死亡率
Python Toolbox

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 Toolbox

関数を定義する

  • 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 Toolbox

まとめ:リスト内包表記

基本

[output expression for iterator variable in iterable]

上級

[output expression + 
conditional on output for iterator variable in iterable +
conditional on iterable]
Python Toolbox

練習しましょう!

Python Toolbox

Preparing Video For Download...