[Tutor] beginning to code

INADA Naoki songofacandy at gmail.com
Tue Sep 12 11:28:39 EDT 2017


> floats = [1.5, 1.9, 2.0, 1.0]
> unique_integers = len(set(int(f) for f in floats))

And it can be written with set comprehension too.

>>> floats = [1.5, 1.9, 2.0, 1.0]
>>> len({int(x) for x in floats})
2

As my personal recommendation, map is OK only
when first argument is predefined.
In other words, I strongly prefer comprehension to map+lambda.

Regards,

INADA Naoki  <songofacandy at gmail.com>



More information about the Python-list mailing list