“Zmień listę ciągów na list Int Python” Kod odpowiedzi

Konwertuj listę ciągów na Ints Python

test_list = ['1', '4', '3', '6', '7'] 

int_list = [int(i) for i in test_list]
EDestroyer

Konwertuj listę na Python Integer

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)
sej

ciąg Python do listy int

>>> example_string = '0, 0, 0, 11, 0, 0, 0, 0, 0, 19, 0, 9, 0, 0, 0, 0, 0, 0, 11'
>>> list(map(int, example_string.split(',')))  # Python 3, in Python 2 the list() call is redundant
[0, 0, 0, 11, 0, 0, 0, 0, 0, 19, 0, 9, 0, 0, 0, 0, 0, 0, 11]
>>> [int(s) for s in example_string.split(',')]
[0, 0, 0, 11, 0, 0, 0, 0, 0, 19, 0, 9, 0, 0, 0, 0, 0, 0, 11]
Unusual Unicorn

Konwertuj listę na liczbę całkowitą w Pythonie

integers = [1, 2, 3]
strings = [str(integer) for integer in integers]
a_string = "". join(strings)
an_integer = int(a_string)
print(an_integer)
Real Rhinoceros

Zmień listę ciągów na list Int Python

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))
Spotless Squirrel

Lista ciągów do listy INT Python

results = [int(i) for i in results]
Clumsy Chimpanzee

Odpowiedzi podobne do “Zmień listę ciągów na list Int Python”

Pytania podobne do “Zmień listę ciągów na list Int Python”

Więcej pokrewnych odpowiedzi na “Zmień listę ciągów na list Int Python” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu