[Tutor] Question on converting a list per say
Hans Fangohr
H.FANGOHR at soton.ac.uk
Mon Sep 6 12:31:42 CEST 2004
Hi Karthik,
> Is it possible to directly convert a list to int/float or complex etc
>
> say a = ['1','2','3']
>
> 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))
Try
b = map( int, a )
I don't know whether this is the fastest way to do it but at least the
notation is concise ;-)
Cheers,
Hans
>
>
> now my a's are quite big like something with 100000 elements? Isint it not
> a slow process to do it like i do?
>
> Warm regards
>
> karthik
>
> PS: Thankx for the regex question - it works with minor modifications
>
> -----------------------------------------------------------------------
> Karthikesh Raju, email: karthik at james.hut.fi
> karthikesh.raju at gmail.com
> Researcher, http://www.cis.hut.fi/karthik
> Helsinki University of Technology, Tel: +358-9-451 5389
> Laboratory of Comp. & Info. Sc., Fax: +358-9-451 3277
> Department of Computer Sc.,
> P.O Box 5400, FIN 02015 HUT,
> Espoo, FINLAND
> -----------------------------------------------------------------------
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------------------------------------------
Dr Hans Fangohr
Computational Engineering & Design Research Group
School of Engineering Sciences
University of Southampton
Southampton, SO17 1BJ
United Kingdom
Location: Building 25, Room 1033
phone : +44 (0) 23 8059 8345
fax : +44 (0) 23 8059 7082
email : fangohr at soton.ac.uk
-------------------------------------------------
More information about the Tutor
mailing list