“ciąg Python do listy int” 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

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

ciąg Python do listy int

[int(s) for s in example_string.split(',')]
Unusual Unicorn

Odpowiedzi podobne do “ciąg Python do listy int”

Pytania podobne do “ciąg Python do listy int”

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

Przeglądaj inne języki kodu