snippetpythonCritical
Convert all strings in a list to integers
Viewed 0 times
allliststringsconvertintegers
Problem
How do I convert all strings in a list to integers?
['1', '2', '3'] ⟶ [1, 2, 3]Solution
Given:
Use
In Python 2,
xs = ['1', '2', '3']Use
map then list to obtain a list of integers:list(map(int, xs))In Python 2,
list was unnecessary since map returned a list:map(int, xs)Code Snippets
xs = ['1', '2', '3']list(map(int, xs))map(int, xs)Context
Stack Overflow Q#7368789, score: 1525
Revisions (0)
No revisions yet.