Te doy la bienvenida a nuestro espacio, ahora vas a encontrar la resolución de lo que buscas.
Ejemplo 1: convertir una lista de cadenas a ints python
test_list =['1','4','3','6','7']
int_list =[int(i)for i in test_list]
Ejemplo 2: cambiar string lista para int lista python
Use the map function (in Python 2.x):
results =map(int, results)
In Python 3, you will need to convert the result frommap to a list:
results =list(map(int, results))
Ejemplo 3: Python convierte una lista de listas de cadenas a 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()
Ejemplo 4: python string a la lista de 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]
Ejemplo 5: convertir lista de cadenas a int python
test_list =['1','4','3','6','7']# Printing original list print("Original list is : "+str(test_list))# using naive method to # perform conversion for i inrange(0,len(test_list)):
test_list[i]=int(test_list[i])# Printing modified list print("Modified list is : "+str(test_list))
Comentarios y puntuaciones del post
Recuerda dar difusión a esta noticia si te valió la pena.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)