
5.1.3. List Comprehensions<http://docs.python.org/dev/tutorial/datastructures.html#list-comprehensions> List comprehensions provide a concise way to create lists. Common applications are to make new lists where each element is the result of some operations applied to each member of another sequence or iterable, or to create a subsequence of those elements that satisfy a certain condition. For example, assume we want to create a list of squares, like:
squares = []>>> for x in range(10):... squares.append(x**2)...>>> squares[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
We can obtain the same result with: squares = [x**2 for x in range(10)] This is also equivalent to squares = map(lambda x: x**2, range(10)), but it’s more concise and readable. I think that the last sentence above should read: squares = list(map(lambda x: x**2, range(10))) In other words, the map function returns a map object, not a list object, so the list() function needs to be used to convert it to something that is truly equivalent to the previous definitions of "squares". (In case it matters, I am using Python-3.3.0rc2 on RHEL 6.3.) Aaron -- Aaron E. Leanhardt, http://www.leanhardtingenuities.com/ * --being ingenious is more valuable than being a genius!*

In other words, the map function returns a map object, not a list object,
Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.
It seems to me that it does return a list object. Am I understanding this correctly? If not, please clarify. Thanks, Mike Hoy

In other words, the map function returns a map object, not a list object,
Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.
It seems to me that it does return a list object. Am I understanding this correctly? If not, please clarify. Thanks, Mike Hoy
participants (2)
-
Aaron Leanhardt
-
Mike Hoy