Converting lists in list to int?

Question:

I have a list empty2 which when prints gives the values:

[]
['0', '0', '0', '16', '25', '31', '36', '45', '46', '42']
['0', '0', '0', '0', '0', '0', '0', '4', '11', '23']
['88', '84', '84', '74', '66', '58', '54', '44', '36', '26']
['14', '15', '15', '8', '9', '5', '6', '6', '7', '7']

The function im calling when trying to call items within this list (the individual lists) wants the values in int format.

But I can’t seem to find a way to convert each list to int, without destroying the list structure within the lists, which needs to be kept. Any help would great.

Asked By: saph_top

||

Answers:

x=[[],
['0', '0', '0', '16', '25', '31', '36', '45', '46', '42'],
['0', '0', '0', '0', '0', '0', '0', '4', '11', '23'],
['88', '84', '84', '74', '66', '58', '54', '44', '36', '26'],
['14', '15', '15', '8', '9', '5', '6', '6', '7', '7']]
print [map(int,i) for i in x ]

This should do it for you.

Output:[[], [0, 0, 0, 16, 25, 31, 36, 45, 46, 42], [0, 0, 0, 0, 0, 0, 0, 4, 11, 23], [88, 84, 84, 74, 66, 58, 54, 44, 36, 26], [14, 15, 15, 8, 9, 5, 6, 6, 7, 7]]

Answered By: vks
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.