You are getting list of empty lists, not empty list
lists are mutable. when you append a to output on line 5, every list you append refers to same elements. when you pop element on line 6 you pop it out from all the lists. To fix this, you need to append copy of a to output
Output:[[], [], [], [], []]
>>>
Check this link https://nedbatchelder.com/text/names.htmllists are mutable. when you append a to output on line 5, every list you append refers to same elements. when you pop element on line 6 you pop it out from all the lists. To fix this, you need to append copy of a to output
a = [1,2,3,4,5] output = [] while a: output.append(a[:]) a.pop(0) print(output)
Output:[[1, 2, 3, 4, 5], [2, 3, 4, 5], [3, 4, 5], [4, 5], [5]]
>>>
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs