Typecasting entries of a list within a list in Python -


i'm looking typecast each entry of list within list in python.

i know map works these sorts of cases:

list = map(int, list) 

but doesn't work cases such this:

for entry in list:     entry = map(int, entry) 

the entries typecast within loop, when loop ends, somehow, each entry reverts original type.

say have list this: [1, 2, 3, 4]. can convert each entry string this: new_list = map(str, [1, 2, 3, 4]) give me ['1', '2', '3', '4']. doesn't work lists within list. [ [1, 2], [3, 4] ] won't convert string using same method.

you need convert output returned map list in python3.

>>> s = [[1, 2, 3, 4], [1, 2, 3, 4]] >>> [list(map(str,i)) in s] [['1', '2', '3', '4'], ['1', '2', '3', '4']] 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -