<div dir="ltr">Just to throw my hat in the ring, this is another way you can do this:<br><br>[(lambda x : [int(ii) for ii in x])(y) for y in a]<br><br>However, I do think dusans way is more elegant.<br><br clear="all">Best,<br>
<br>R<br><br><div class="gmail_quote">On Tue, Jul 22, 2008 at 4:58 PM, dusans <<a href="mailto:dusan.smitran@gmail.com">dusan.smitran@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">>>> a = [['1', '2'], ['3'], ['4', '5', '6'], ['7', '8', '9', '0']]<br>
</div>>>> [map(int, i) for i in a]<br>
[[1, 2], [3], [4, 5, 6], [7, 8, 9, 0]]<br>
<div><div></div><div class="Wj3C7c"><br>
On Jul 21, 9:06 pm, Samir <<a href="mailto:spytho...@gmail.com">spytho...@gmail.com</a>> wrote:<br>
> Hi Everyone,<br>
><br>
> I am relatively new to Python so please forgive me for what seems like<br>
> a basic question.<br>
><br>
> Assume that I have a list, a, composed of nested lists with string<br>
> representations of integers, such that<br>
><br>
> a = [['1', '2'], ['3'], ['4', '5', '6'], ['7', '8', '9', '0']]<br>
><br>
> I would like to convert this to a similar list, b, where the values<br>
> are represented by integers, such as<br>
><br>
> b = [[1, 2], [3], [4, 5, 6], [7, 8, 9, 0]]<br>
><br>
> I have unsuccessfully tried the following code:<br>
><br>
> n = []<br>
> for k in a:<br>
>     n.append([int(v) for v in k])<br>
> print n<br>
><br>
> Does anyone know what I am doing wrong?<br>
><br>
> Thanks in advance.<br>
><br>
> Samir<br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br></div>