spliting a list by nth items
m.h.3.9.1.without.dots.at.cam.ac.uk at example.com
Thu Sep 23 20:30:01 CEST 2004
Larry Bates wrote:
> I believe you meant somthing like:
> non_nth_items = [items[i-1] for i in range(1,len(items)-1) if i % n]
> I don't think the "if x % n" won't work on his list of items
D'oh! I wasn't thinking--the test list of items I used was
range(something), so of course it worked.
What I meant <wink> was:
non_nth_items = [x for index, x in enumerate(items) if index % n]
Thanks for the correction.
More information about the Python-list