Reputation: 65
I have a set
set1= { '1', '2' }
I want to convert '1', '2' to int , like this :
set_new = { 1, 2 }
How can I do this in python?
Upvotes: 2
Views: 10208
Reputation: 123
You can use set comprehension:
>>> set1={'1', '2'}
>>> set2={int(item) for item in set1}
>>> set2
{1, 2}
Upvotes: 0
Reputation: 10223
Use map function
Demo:
>>> set1= { '1', '2' }
>>> set2 = set(map(int, set1))
>>> set2
set([1, 2])
Upvotes: 11