Python: Reading n lines at a time in a list -


i'm new python know there has more elegant way , hoping advice on this.

currently, have list consists of x entries. want to:

  • read n entries list @ time
  • do computation n entries (calculating standard deviation, need mean of n entries)
  • move on next n entries, , calculation new set of data
  • append these values file

right now, i'm going primitive , doing like:

first = mylist[0:11] mean = sum(first)/nentries second = mylist{11:22] mean2 = sum(second)/nentries ... 

as can see, extremely novice , not elegant @ if have 352 entries , need read 11 lines @ time them. there easy way loop on list , pick out n entries (in case, 11) @ time? thanks!

why not using range:

range(start, stop[, step]) -> list of integers 

in case:

for start in range(0,len(mylist), 11):     end = start + 11     blablabla 

or itertools.count:

range(start, stop[, step]) -> list of integers 

Comments