xxxxxxxxxx
Use the map function (in Python 2.x):
results = map(int, results)
In Python 3, you will need to convert the result from map to a list:
results = list(map(int, results))
xxxxxxxxxx
test_list = ['1', '4', '3', '6', '7']
int_list = [int(i) for i in test_list]
xxxxxxxxxx
num = [1, 2, 3, 4]
s = [str(i) for i in num] # Converting integers into strings
result = str("".join(s)) # Join the string values into one string
print(result)
xxxxxxxxxx
# Basic syntax:
list_of_ints = [int(i) for i in list_of_strings]
# Example usage with list comprehension:
list_of_strings = ['2', '3', '47']
list_of_ints = [int(i) for i in list_of_strings]
print(list_of_ints)
--> [2, 3, 47]
xxxxxxxxxx
integers = [1, 2, 3]
strings = [str(integer) for integer in integers]
a_string = "". join(strings)
an_integer = int(a_string)
print(an_integer)
xxxxxxxxxx
# Python3 program to convert a list
# of integers into a single integer
def convert(list):
# Converting integer list to string list
# and joining the list using join()
res = int("".join(map(str, list)))
return res
# Driver code
list = [1, 2, 3]
print(convert(list))
xxxxxxxxxx
List<String> stringList = new ArrayList<String>(Arrays.asList("10", "30", "40",
"50", "60", "70"));
List<Integer> integerList = stringList.stream()
.map(Integer::valueOf).collect(Collectors.toList());
xxxxxxxxxx
list_of_strings = ['1', '5', '7', '45', '67']
list_of_ints = [int(item) for item in list_of_strings]
print(list_of_ints)
xxxxxxxxxx
# Example usage using list comprehension:
# Say you have the following list of lists of strings and want integers
x = [['565.0', '575.0'], ['1215.0', '245.0'], ['1740.0', '245.0']]
list_of_integers = [[int(float(j)) for j in i] for i in x]
print(list_of_integers)
--> [[565, 575], [1215, 245], [1740, 245]]
# Note, if the strings don't have decimals, you can omit float()