Python Forum
I don't understand this result
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I don't understand this result
#5
(Mar-27-2017, 12:10 PM)buran Wrote: just to mention that there is no need to explicitly convert the result to list
Python 3 has changed a lot buran Wink
# 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.
Reply


Messages In This Thread
RE: I don't understand this result - by zivoni - Mar-27-2017, 12:04 PM
RE: I don't understand this result - by Larz60+ - Mar-27-2017, 12:07 PM
RE: I don't understand this result - by buran - Mar-27-2017, 12:10 PM
RE: I don't understand this result - by snippsat - Mar-27-2017, 01:53 PM
RE: I don't understand this result - by buran - Mar-27-2017, 02:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Two same codes, different result. Please help to understand. vickyprabhat 5 3,687 Mar-24-2018, 11:33 PM
Last Post: vickyprabhat
  I don't understand this result Ponomarenko Pavlo 3 3,870 Jan-15-2017, 04:40 PM
Last Post: Kebap

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020