“Liste de partage de Python” Réponses codées

Cliver la liste en liste des listes Python sur chaque élément 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

Séparez une chaîne en 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

Python Spliting String dans la liste

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

Liste de partage de 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

Liste de partage de 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

Réponses similaires à “Liste de partage de Python”

Questions similaires à “Liste de partage de Python”

Plus de réponses similaires à “Liste de partage de Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code