Tuple of strings to integers
Write a Python program to convert a tuple of numeric strings to integers, ignoring stray commas.
("4563", "68", "1,")(4563, 68, 1)
Approach
- Strip the commas, then
int()each value.
Solution
t = ("4563", "68", "1,")print(tuple(int(s.replace(",", "")) for s in t))(4563, 68, 1)
Learn the concept
New to this topic? Read the lesson, then come back.