0

I have a list which may be of any length. I have a method which calculates results for 50 elements at a time. I want to use the list in that manner such that for every iteration i get the next 50 elements.

What is did is, with the length of the list i calculated the no of times my loop should iterate,

count = math.ceil(len(newList)/float(50))

how should i iterate such that i can get the next 50 elements every iteration?

for c in range(0,count):
    newList[:50]

how to get the next 50 and then next 50 ?

tom
  • 18,953
  • 4
  • 35
  • 35
siddaqui
  • 129
  • 1
  • 1
  • 7

1 Answers1

1

I would go for something like this:

for c in range(0,int(count)):
    print newList[c*50:(c+1)*50]
charles
  • 713
  • 1
  • 6
  • 16