Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-14 Thread spir
On 12/14/2013 10:12 AM, Bo Morris wrote: Thank you for your assistance. Based on your direction, I figured it out. *This... * def add(number): print 1 + int(number) x = ['2', '4', '6', '8', '10', '12'] [add(item) for item in x] *Is the same as... * def add(number): print 1 +

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-14 Thread Peter Otten
Bo Morris wrote: > Thank you for your assistance. Based on your direction, I figured it out. > > *This... * > > def add(number): > print 1 + int(number) > > x = ['2', '4', '6', '8', '10', '12'] > > [add(item) for item in x] > > *Is the same as... * > > > def add(number): > print

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-14 Thread Bo Morris
Thank you for your assistance. Based on your direction, I figured it out. *This... * def add(number): print 1 + int(number) x = ['2', '4', '6', '8', '10', '12'] [add(item) for item in x] *Is the same as... * def add(number): print 1 + int(number) x = ['2', '4', '6', '8', '10', '1

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-13 Thread Steven D'Aprano
On Fri, Dec 13, 2013 at 08:03:57PM -0500, Bo Morris wrote: > i have the following simple function that iterates over the list. Actually, no it doesn't. One important skill of being a programmer is precision of language. The function "add" you show below does not iterate over the list, it is th

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-13 Thread Amit Saha
On Sat, Dec 14, 2013 at 11:03 AM, Bo Morris wrote: > i have the following simple function that iterates over the list. It passes > the list item into the function and adds the numbers. What would be the > equivalent way of writing the "map" portion with list comprehension? My code > is as follows:

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-13 Thread Mark Lawrence
On 14/12/2013 01:03, Bo Morris wrote: i have the following simple function that iterates over the list. It passes the list item into the function and adds the numbers. What would be the equivalent way of writing the "map" portion with list comprehension? My code is as follows: def add(number):

[Tutor] list comprehension equivalent to map(function, list item)

2013-12-13 Thread Bo Morris
i have the following simple function that iterates over the list. It passes the list item into the function and adds the numbers. What would be the equivalent way of writing the "map" portion with list comprehension? My code is as follows: def add(number): print 1 + int(number) x = ['2', '4