“Python Split -Liste” Code-Antworten

Teilen Sie die Liste in Liste der Listen Python in jedem N -Element auf

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

Trennen Sie eine Zeichenfolge in 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 in die Liste

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

Python Split -Liste

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

Python Split -Liste

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

Ähnliche Antworten wie “Python Split -Liste”

Fragen ähnlich wie “Python Split -Liste”

Weitere verwandte Antworten zu “Python Split -Liste” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen