[Baypiggies] python list manipulation using map

joshua kaderlan jkaderlan at yahoo.com
Tue May 3 00:51:50 CEST 2011



That's actually a map() call inside a list comprehension. Either a bare map() call or a list comprehension without the map() call will do what you want. 


E.g.,
>>> T2 = map(lambda i: int(i), x)

or 


>>> T2 = [int(i) for i in x]




>________________________________
>From: Vikram K <kpguy1975 at gmail.com>
>To: baypiggies at python.org
>Sent: Monday, May 2, 2011 3:37 PM
>Subject: [Baypiggies] python list manipulation using map
>
>
>i have a list whose elements are strings. all the elements in the list are numbers but are represented as string type and i wish to convert them to int type. i tried using map but the output is not what i want. please help.
>
> x = ['0', '0', '20', '15', '42', '0', '0', '0', '0', '0', '0', '0', '0', '52', '57', '0', '254', '0', '177', '0', '617', '1021979']
>
>>>> T2 = [map(int, i) for i in x]
>>>> T2
>[[0], [0], [2, 0], [1, 5], [4, 2], [0], [0], [0], [0], [0], [0], [0], [0], [5, 2], [5, 7], [0], [2, 5, 4], [0], [1, 7, 7], [0], [6, 1, 7], [1, 0, 2, 1, 9, 7, 9]]
>
>----------
>
>
>_______________________________________________
>Baypiggies mailing list
>Baypiggies at python.org
>To change your subscription options or unsubscribe:
>http://mail.python.org/mailman/listinfo/baypiggies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20110502/a5caeaa3/attachment.html>


More information about the Baypiggies mailing list