Timeline for answer to Make a new list containing every Nth item in the original list by Denis Otkidach
Current License: CC BY-SA 4.0
Post Revisions
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 16, 2019 at 15:25 | history | edited | Mark Amery | CC BY-SA 4.0 |
typo fix, and hyphenated compound adjective
|
| Aug 5, 2016 at 17:01 | history | edited | Denis Otkidach | CC BY-SA 3.0 |
deleted 1 character in body
|
| Sep 15, 2009 at 13:01 | comment | added | Denis Otkidach | Iterable = object with __iter__() method returning iterator (object with next() method) | |
| Sep 10, 2009 at 9:59 | comment | added | ThomasH | +1 Best answer, IMO. All three proposals a general solutions (ie. take the source list as a given). The generator solution (3.) is nice as it filters on the index of the source list. It's probably as memory efficient as 2. Both the indices and the result list are generators and thus constructed lazily, which is also probably the fastest if you don't need the result list in a single chunk. Only if the source list could be a generator I would go with Paul's "item, i in enumerate(l)" idiom, as there is no len() of a generator. BTW, which kind of iterable would not work with 1.? Generators?! | |
| Sep 10, 2009 at 9:16 | history | edited | SilentGhost | CC BY-SA 2.5 |
deleted 1 characters in body
|
| Sep 10, 2009 at 9:13 | history | answered | Denis Otkidach | CC BY-SA 2.5 |