Mar-27-2017, 01:53 PM
(Mar-27-2017, 12:10 PM)buran Wrote: just to mention that there is no need to explicitly convert the result to listPython 3 has changed a lot buran
# Python 3.6 >>> def az(x): ... return x*2 ... >>> q = map(az, [2, 3, 4]) >>> q <map object at 0x049C8EB0> >>> list(q) [4, 6, 8]
# Python 2.7 >>> def az(x): ... return x * 2 ... >>> q = map(az, [2, 3, 4]) >>> q [4, 6, 8]Built-ins like range, map, zip, filter become iterables in 3.x to conserve space,
rather than producing a result list all at once in memory.