[Tutor] beginning to code

Chris Angelico rosuav at gmail.com
Sun Sep 10 21:58:15 EDT 2017


On Mon, Sep 11, 2017 at 11:29 AM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> Ruby:
>     farray = [1.5, 1.9, 2.0, 1.0]
>     uniqueIntegers = farray.map{|f| f.to_i()}.uniq.length
>
> Python:
>     flist = [1.5, 1.9, 2.0, 1.0]
>     uniqueIntegers = len(set(map(lambda f:int(f), flist)))

Python:

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

or:

unique_integers = len(set(map(int, floats))

If you're going to use Python, at least use it right.

ChrisA



More information about the Python-list mailing list