spliting a list by nth items
steven.bethard at gmail.com
Thu Sep 23 19:25:32 CEST 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)
Is this the right way to do this?
You can wordify anything if you just verb it.
- Bucky Katt, Get Fuzzy
More information about the Python-list