Add key
argument to tuple.index()
· Issue #113779 · python/cpython (original) (raw)
Feature or enhancement
Proposal:
It would be useful to search a tuple in a functional-style manner
tuple with structured data
data = ((1, 2), (2, 3))
find index of 2 in classic manner:
for idx, item in enumerate(data): if item[1] == 2: break
functional-style search:
idx = data.index(2, key=lambda i: i[1])
This manner is same to list.sort for example
data = [(1, 2), (2, 3)] data.sort(key=lambda g: g[1])
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
Same functionality was discussed in #113773 but for list.index()