spliting a list by nth items

Steven Bethard steven.bethard at gmail.com
Thu Sep 23 13:25:32 EDT 2004


I feel like this has probably been answered before, but I couldn't
find something quite like it in the archives.  Feel free to point me
somewhere if you know where this has already been answered.

I have a list in a particular order that I want to split into two
lists: the list of every nth item, and the list of remaining items. 
It's important to maintain the original order in both lists.

So the first list is simple:

nth_items = items[::n]

The second list is what's giving me trouble.  So far, the best I've
come up with is:

non_nth_items = list(items)
del non_nth_items[::n]

Is this the right way to do this?

Steve
-- 
You can wordify anything if you just verb it.
        - Bucky Katt, Get Fuzzy



More information about the Python-list mailing list