“Lista de divisão do Python” Respostas de código

Lista dividida na lista de listas Python em cada elemento N

big_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
x = 4
list_of_lists = [big_list[i:i+x] for i in range(0, len(big_list), x)]
# [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
Anxious Alligator

Separe uma string em python

spam = "A B C D"
eggs = "E-F-G-H"

# the split() function will return a list
spam_list = spam.split()
# if you give no arguments, it will separate by whitespaces by default
# ["A", "B", "C", "D"]

eggs_list = eggs.split("-", 3)
# you can specify the maximum amount of elements the split() function will output
# ["E", "F", "G"]
Drab Dormouse

string de divisão de python na lista

text = 'This is python!
x = text.split()
print(x)
Pixel 2075

Lista de divisão do Python

list = [11, 18, 19, 21]

length = len(list)

middle_index = length // 2

first_half = list[:middle_index]
second_half = list[middle_index:]

print(first_half)
print(second_half)
Brave Butterfly

Lista de divisão do Python

string = "this is a string" 		# Creates the string
splited_string = string.split(" ")	# Splits the string by spaces
print(splited_string) 				# Prints the list to the console
# Output: ['this', 'is', 'a', 'string']
VL07

Respostas semelhantes a “Lista de divisão do Python”

Perguntas semelhantes a “Lista de divisão do Python”

Mais respostas relacionadas para “Lista de divisão do Python” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código