Converting List of String to Integer
John Machin
sjmachin at lexicon.net
Mon Jul 21 16:33:01 EDT 2008
On Jul 22, 6:11 am, Samir <spytho... at gmail.com> wrote:
[snip]
> For some reason, the logic I posted seems to work ok while I'm using
> the Python shell, but when used in my code, the program just hangs.
> It never outputs the results. Below is the code in its entirety. Is
> there a problem with my indendentation?
>
> a = n = []
> t = """
> 1 2
> 3
> 4 5 6
> 7 8 9 0
> """
>
> d = t.split("\n")
>
> for x in range(1,len(d)-1):
> a.append(d[x].split(" "))
> print a
>
> for k in a:
> n.append([int(v) for v in k])
To see what is happening, insert some print statements, plus something
to slow it down e.g.
for k in a:
print id(a), a
print id(n), n
n.append([int(v) for v in k])
raw_input('Hit Enter to continue ->')
>
> print n
>
More information about the Python-list
mailing list