How to remove an item from a tuple in Python

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Sometimes it only remove first (), sometime only add on new new_tuple_list not full list pls have look and tell me can u help here when we cant update it then why is there remove method in tuples

# remove empty tuples from arraylist
tuple_list =[( ), ( ), ('a', 'b'), ('a', 'b', 'c'), ('d')]

# create an empty list
new_tuple_list=[]

for i in tuple_list:
if len(i)>0:
new_tuple_list.append(i)
else:
tuple_list.remove(i)
print(tuple_list)

print(new_tuple_list)

johnmartin
welcome to shbcf.ru