osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tutor] beginning to code


> 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>