Python Forum
list, map and put of the Queue in the Tree Data Structure
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list, map and put of the Queue in the Tree Data Structure
#3
map transforms the items in a iterable in some way. The iterable is passed as the second argument and a function that performs the transformation as the first. So, map calls the function on each of the items in the iterable producing a new one. It actually produces a generator, so list there turns that generator into a list.

The class in the example above adds nothing, other than a bit of noise.

>>> def double(x):
...     return 2 * x
... 
>>> values = [1, 7, 4, 10, 9]
>>> list(map(double, values))
[2, 14, 8, 20, 18]
A list comprehension does the same:

>>> [double(v) for v in values]
[2, 14, 8, 20, 18]
longmen likes this post
Reply


Messages In This Thread
RE: list, map and put of the Queue in the Tree Data Structure - by ndc85430 - Mar-30-2022, 05:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  A data structure akulamartin 5 5,413 Nov-11-2016, 07:22 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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