0

Suppose I have a list of items M=[(1,2),(2,11),(3,11),(4,11),(5,11),(6,11),(7,11),(8,11),(9,11)]

Now I want to retrieve first 3 items in the list (1,2)(2,11)(3,11), add them up and next retrieve another 3 items in list (4,11)(5,11)(6,11) and so on till the end of the list.

list=[]
for a, b in M:
     if length(list)==3:
         list.append(b)
     return sum(list)

What is the effective way to write the retrieve the first 3 elements, next 3 and so on.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Ayesha
  • 53
  • 7

0 Answers0