“Hapus daftar nilai dari daftar python” Kode Jawaban

Hapus daftar nilai dari daftar python

# Python program to remove multiple
# elements from a list
 
# creating a list
list1 = [11, 5, 17, 18, 23, 50]
 
# items to be removed
unwanted_num = {11, 5}
 
list1 = [ele for ele in list1 if ele not in unwanted_num]
 
# printing modified list
print("New list after removing unwanted numbers: ", list1)
Confused Crocodile

Hapus daftar nilai dari daftar python

# Python program to remove multiple
# elements from a list
 
# creating a list
list1 = [11, 5, 17, 18, 23, 50]
 
# given index of elements
# removes 11, 18, 23
unwanted = [0, 3, 4]
 
for ele in sorted(unwanted, reverse = True):
    del list1[ele]
 
# printing modified list
print (*list1)
Confused Crocodile

Jawaban yang mirip dengan “Hapus daftar nilai dari daftar python”

Pertanyaan yang mirip dengan “Hapus daftar nilai dari daftar python”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya