“Daftar Split Python” Kode Jawaban

Daftar terpisah ke dalam daftar daftar Python di setiap elemen 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

pisahkan string dalam 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 ke dalam Daftar

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

Daftar Split 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

Daftar Split 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

Jawaban yang mirip dengan “Daftar Split Python”

Pertanyaan yang mirip dengan “Daftar Split Python”

Lebih banyak jawaban terkait untuk “Daftar Split Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya