Lawrence D’Oliveiro <lawrenced...@gmail.com> writes:

> On Tuesday, August 16, 2016 at 6:26:01 PM UTC+12, Paul Rudin wrote:
>> sohcahtoa82 writes:
>>> squared_plus_one_list = map(lambda x: x**2 + 1, some_list)
>> 
>> I realise that this is about understanding lambda, but it's worth noting
>> in passing that we tend to write this sort of thing as:
>> 
>> squared_plus_one_list = [x**2 + 1 for x in some_list]
>
> The difference being that the “map” function takes an iterable and returns an 
> iterator.

Ah well - that depends the python version. Since the OP used a name
including the substring 'list' I assumed python 2.


> Why could this difference be important?

The main thing is to understand the difference, and then it's possible
to reason about whether it matters in a given context.

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to