0

I am trying to understand use of :. I have below example code. I am not getting what the last line is doing. Please explain. Also please share how or when to use :

listoflists = []
list = []
for i in range(0,10):
    list.append(i)
    if len(list)>3:
        list.remove(list[0])
        listoflists.append((list, list[0]))
print (listoflists)

print (listoflists[:][0][1])#print y values only for the first batch, : for all batches 
print (listoflists[0][1])
print(listoflists[:])
user2543622
  • 5,760
  • 25
  • 91
  • 159
  • `[:]` is the nothing index. That is to say that `[1,2,3,4,5][:] == [1,2,3,4,5]` – kpie Feb 11 '20 at 23:41
  • @kpie Wouldn't that make it the "*everything* index"? Have a link to the "nothing index" terminology? – user2864740 Feb 11 '20 at 23:50
  • @kpie could you show when `[:]` could be used to do something useful? – user2543622 Feb 12 '20 at 00:39
  • It's the equivalent of saying `a[0:len(a)]` which is equivalent to just saying `a` I really can't think of any case where it is helpful other than as a placeholder during debug. – kpie Feb 12 '20 at 13:04

0 Answers0