Slide 49
Slide 49 text
Pythonのmap
# mapはiterableなオブジェクト全てに関数を適応します
# 返り値はIteratorなのでlist function等を適応する必要があります
map(str, [1, 2, 3]) #
list(map(str, [1, 2, 3])) # ["1", "2", "3"]
# mapの第一引数にlistを入れると第2引数のiteratorを回してlist化します
list(map(list, '123')) # [["1"], ["2"], ["3"]]
# mapの第2引数以降はzipのように扱えます
# これを利用してmapの中にmapを書いてみます
map(map, [list,list,list], "abc") # 実質 [map(list, “a”), map(list, “b”), map(list, “c”)]