“Converter Lista de Strings em Ints Python” Respostas de código

Converter Lista de Strings em Ints Python

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

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

Alterar a lista de string para int list 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

string python para listar 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

Lista de strings para números Python

test_list = ['1', '4', '3', '6', '7']
test_list = list(map(int, test_list))
WIP

string python para listar int

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

python converter lista de listas de strings para int

# 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()
Charles-Alexandre Roy

Respostas semelhantes a “Converter Lista de Strings em Ints Python”

Perguntas semelhantes a “Converter Lista de Strings em Ints Python”

Mais respostas relacionadas para “Converter Lista de Strings em Ints Python” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código