python特殊関数のlambdaとmap


Lambda式は関数オブジェクトを返します
map(function,sequence)は、sequenceの値をfunctionに1つずつ渡し、関数実行結果を含むlistを返す
例:
squares = list(map(lambda x: x**2, range(10)))
squares値Yes
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

次のようになります.
squares = [x**2 for x in range(10)]

次のようになります.
>>> squares = []>>> for x in range(10):
...     squares.append(x**2)