String to list without using regex
If I have a string as in
mystring = "1212, 1215, 2132, 2312, 3333"
What is the recommended approach to convert it into a list? as in
mylist = [1212, 1215, 2132,开发者_开发问答 2312, 3333]
Please note that mystring can assume a single value too, as in mystring = "1212"
map(int, mystring.split(','))
That's it.
List comprehension syntax:
[int(n) for n in mystring.split(',')]
精彩评论