LoginSignup
0
0

More than 3 years have passed since last update.

iterator および generator (Python)

Last updated at Posted at 2019-08-01

こんにちは。
Python で、iterable を引数に取る関数を試し、イテレータ (iterator) である [1,2] および、ジェネレータイテレータ (generator iterator) である x for x in [1,2] を与えてみました。

sum() で試すと、

>> max([1,2])
2
>> max(x for x in [1,2])
2

map() で試すと、

>> list(map(lambda x: x*x, [1,2]))
[1, 4]
>> list(map(lambda x: x*x, (x for x in [1,2])))
[1, 4]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0