Python Program To Remove Empty Tuples From A List|Python Programs For Begginers

preview_player
Показать описание
The above video is about removing empty tuples from a list.This program may help you to understand the concept of lists and tuples.If you have any doubts,reach me out at the commenta section.
This program can be written as:
-Create a list containing tuples.
-loop over the tuples within the list.
-check if the length of the tuple is '0' or not.
-remove the tuples of length '0'.
-Print the list.
Рекомендации по теме
Комментарии
Автор

Saw a code online which was a one line code goes like this:
new_list=[x for x in list if x]
and it worked, can u tell how does this work?

shaurya
Автор

In your same program, if I take list as [(), (), (), (1, 2, 3), (4, 5), (), (), (), ()] then in output I am getting [(1, 2, 3), (4, 5), (), (), ()]. Out of 7 only 4 empty tuples are removed and still shows 3 empty tuples.
Why it is showing output like this ?

kannankalyanasundaram
welcome to shbcf.ru