[Tutor] Re: Question on converting a list per say

Andrei project5 at redrival.net
Mon Sep 6 13:36:22 CEST 2004


Karthikesh Raju <karthik <at> james.hut.fi> writes:

> can i do an int(a) to get [1,2,3] or a float(a).
> 
> Presenly i do:
> b = []
> for vals in a
>     b.append(int(a))
> 
> now my a's are quite big like something with 100000 elements? Isint it not
> a slow process to do it like i do?

It probably is, but is it slow enough for you notice it? You could try a list
comprehension:

b = [int(val) for val in a]

I don't know how this compares speed-wise with the map() solution already
offered, but I like list comprehensions better than map() anyway :). You could
do a benchmark if this part of your application is critical. 

Yours,

Andrei



More information about the Tutor mailing list