
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2016-06-04 05:33 byalex0307, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| islice_my.py | alex0307,2016-06-04 05:33 | A simple fix of islice() | ||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 6195 | merged | cheryl.sabella,2018-03-22 23:27 | |
| PR 6266 | merged | miss-islington,2018-03-27 01:30 | |
| PR 6267 | merged | miss-islington,2018-03-27 01:31 | |
| PR 6339 | merged | cheryl.sabella,2018-04-01 22:53 | |
| Messages (11) | |||
|---|---|---|---|
| msg267236 -(view) | Author: alex0307 (alex0307) | Date: 2016-06-04 05:33 | |
In the doc for itertools, the python implementation of islice() doesn't actually perform the iteration when given an empty slice (e.g. islice(it,3,3)). This is not the expected behavior for 'consume()' in the recipe given below, i.e. consume(it,3) couldn't actually advance the iterator for 3 steps ahead. Instead, the iterator stays at its starting position.As a simple fix, in the implementation of islice(), the length of the slice object should be checked first. If it's zero, the iterator should be advanced (slice.start-1) times, and return (See islice_my.py) | |||
| msg275432 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2016-09-09 20:44 | |
The recipe should be modified to consume the initial values. Something like this: start, stop, step = s.start or 0, s.stop or sys.maxsize, s.step or 1 for i in zip(range(0, start), it): passThe recipe needs to pass these tests: it = iter('abcdefghi') assert list(islice(it, 4, 4)) == [] assert list(it) == ['e', 'f', 'g', 'h', 'i'] assert(list(islice('ABCDEFG', 2)) == ['A', 'B']) assert(list(islice('ABCDEFG', 2, 4)) == ['C', 'D']) assert(list(islice('ABCDEFG', 2, None)) == ['C', 'D', 'E', 'F', 'G']) assert(list(islice('ABCDEFG', 0, None, 2)) == ['A', 'C', 'E', 'G']) | |||
| msg314164 -(view) | Author: Cheryl Sabella (cheryl.sabella)*![]() | Date: 2018-03-20 20:20 | |
Hi Nofar,Are you still interested in working on this issue? Thanks! | |||
| msg314235 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2018-03-22 06:38 | |
Cheryl, I think you take this one. It hasn't been touched in a long time and Nofar is focused on another issue. | |||
| msg314269 -(view) | Author: Cheryl Sabella (cheryl.sabella)*![]() | Date: 2018-03-22 16:05 | |
Thanks, Raymond. I'll take a look. | |||
| msg314490 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2018-03-27 01:29 | |
New changesetda1734c58d2f97387ccc9676074717d38b044128 by Raymond Hettinger (Cheryl Sabella) in branch 'master':bpo-27212: Modify islice recipe to consume initial values preceding start (GH-6195)https://github.com/python/cpython/commit/da1734c58d2f97387ccc9676074717d38b044128 | |||
| msg314491 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2018-03-27 02:23 | |
New changesetf328caf4caafd4521c356af8cb8a299f27603c90 by Raymond Hettinger (Miss Islington (bot)) in branch '3.7':bpo-27212: Modify islice recipe to consume initial values preceding start (GH-6195) (#GH-6266)https://github.com/python/cpython/commit/f328caf4caafd4521c356af8cb8a299f27603c90 | |||
| msg314492 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2018-03-27 02:24 | |
New changesetc8698cff7ccc8dc730c58523c7ef4113ea8d3049 by Raymond Hettinger (Miss Islington (bot)) in branch '3.6':bpo-27212: Modify islice recipe to consume initial values preceding start (GH-6195) (GH-6267)https://github.com/python/cpython/commit/c8698cff7ccc8dc730c58523c7ef4113ea8d3049 | |||
| msg314800 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2018-04-02 05:29 | |
New changeset325191bd6b3a2d5e3012adee868f19baf3e2c3ab by Raymond Hettinger (Cheryl Sabella) in branch '2.7':[2.7]bpo-27212: Modify islice recipe to consume initial values preceding start (GH-6195) (GH-6339)https://github.com/python/cpython/commit/325191bd6b3a2d5e3012adee868f19baf3e2c3ab | |||
| msg314801 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2018-04-02 05:29 | |
Thanks Cheryl. This was nice work :-) | |||
| msg314816 -(view) | Author: Cheryl Sabella (cheryl.sabella)*![]() | Date: 2018-04-02 17:36 | |
Thanks! :-) | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:32 | admin | set | github: 71399 |
| 2018-04-02 17:36:40 | cheryl.sabella | set | messages: +msg314816 |
| 2018-04-02 05:29:54 | rhettinger | set | status: open -> closed resolution: fixed messages: +msg314801 stage: patch review -> resolved |
| 2018-04-02 05:29:05 | rhettinger | set | messages: +msg314800 |
| 2018-04-01 22:53:37 | cheryl.sabella | set | pull_requests: +pull_request6051 |
| 2018-03-27 02:24:04 | rhettinger | set | messages: +msg314492 |
| 2018-03-27 02:23:36 | rhettinger | set | messages: +msg314491 |
| 2018-03-27 01:31:43 | miss-islington | set | pull_requests: +pull_request5992 |
| 2018-03-27 01:30:51 | miss-islington | set | pull_requests: +pull_request5991 |
| 2018-03-27 01:29:36 | rhettinger | set | messages: +msg314490 |
| 2018-03-22 23:27:53 | cheryl.sabella | set | keywords: +patch stage: patch review pull_requests: +pull_request5942 |
| 2018-03-22 16:05:44 | cheryl.sabella | set | messages: +msg314269 |
| 2018-03-22 06:38:35 | rhettinger | set | assignee:Nofar Schnider ->cheryl.sabella messages: +msg314235 |
| 2018-03-20 20:20:53 | cheryl.sabella | set | nosy: +cheryl.sabella messages: +msg314164 |
| 2016-09-09 20:45:52 | rhettinger | set | assignee:rhettinger ->Nofar Schnider nosy: +Nofar Schnider |
| 2016-09-09 20:44:00 | rhettinger | set | messages: +msg275432 |
| 2016-06-04 05:41:29 | serhiy.storchaka | set | assignee:docs@python ->rhettinger nosy: +rhettinger |
| 2016-06-04 05:33:46 | alex0307 | create | |