I want to know what does list[:0] means. In the following code what it is doing?
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
k=[]
while len(k) < 20:
for i in LETTERS:
k[:0] = i
print(k)
# k = ['Z', 'Y', 'X', 'W', 'V', 'U', 'T', 'S', 'R', 'Q', 'P', 'O', 'N', 'M', 'L', 'K', 'J', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A']
- Shouldn't the loop break when
len(k)==20
? - If
k[:0]
is an empty list, why every time there isn't a list inside k?? - Does
k[:0]
works like a stack and pushes the older items?