It's very common to see:
```
for i, x in enumerate(sequence):
[...]
```
and also to see
```
for i in range(len(sequence)):
[...]
```
I propose to introduce for sequences the methods `indexes()` and `entries()`.
They are similar to `keys()` and `items()` for maps. I changed the names for
not doing a breaking change.
This way the two codes will became simply:
```
for i, x in sequence.entries():
[...]
for i in sequence.indexes():
[...]
```
sequence.indexes() could return:
1. a SequenceIndexesView, similar to the views of `dict`
2. a simple range() object
The same for entries(). It should be:
1. a SequenceEntriesView
2. a generator that yields the tuples (index, value)
What do you think about?
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/UHIB3CYI7LEHQEHZ5C54DT5NXMQU42NZ/
Code of Conduct: http://python.org/psf/codeofconduct/