python / cpython

The Python programming language
https://www.python.org
Other
63.15k stars 30.24k forks source link

turning itertools.{repeat,count} into indexable iterables #68059

Closed 379dc349-3a10-424f-b9d2-a0104f092359 closed 9 years ago

379dc349-3a10-424f-b9d2-a0104f092359 commented 9 years ago
BPO 23871
Nosy @rhettinger, @bitdancer, @anntzer, @ztane

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = created_at = labels = ['library'] title = 'turning itertools.{repeat,count} into indexable iterables' updated_at = user = 'https://github.com/anntzer' ``` bugs.python.org fields: ```python activity = actor = 'r.david.murray' assignee = 'none' closed = True closed_date = closer = 'r.david.murray' components = ['Library (Lib)'] creation = creator = 'Antony.Lee' dependencies = [] files = [] hgrepos = [] issue_num = 23871 keywords = [] message_count = 3.0 messages = ['240096', '240105', '240132'] nosy_count = 4.0 nosy_names = ['rhettinger', 'r.david.murray', 'Antony.Lee', 'ztane'] pr_nums = [] priority = 'normal' resolution = 'rejected' stage = 'resolved' status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue23871' versions = ['Python 3.5'] ```

379dc349-3a10-424f-b9d2-a0104f092359 commented 9 years ago

itertools.repeat and itertools.count could be made into indexable iterables (rather than iterators), rather than iterators, like range is right now.

ff59cd45-ebe3-4b3e-9696-65dc59a38b8c commented 9 years ago

well, they wouldn't and shouldn't behave like range. range is a sequence whereas count or repeat wouldn't necessarily be sequences. (they can be infinite and thus not having length). And the count shouldn't be *reiterable* because that is why it exists (otherwise we could just use range). For repeat, indexing hardly matters.

bitdancer commented 9 years ago

I agree with Antti. If Raymond disagrees he can reopen :)

(There is a reason it is called *iter*tools. As Antti says, range is documented as being a *sequence* type.)