Issue
I have a list like this:
id=['"1',
'"1',
'"2',
'"2',
'"1',
'"1',
'"2',
'"2'
]
what is the best way to convert all the item to numbers, now they are strings.Out put should like:
id=[1,
1,
2,
2,
...
2]
Solution
You can try:
numbers = [int(s.replace('"', '')) for s in id]
print(numbers)
# [1, 1, 2, 2, 1, 1, 2, 2]
and please don't use id
as a variable name, as it's already a name used by python
Answered By - Be Chiller Too
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.