Visitar URL original
Add `key` argument to `tuple.index()` · Issue #113779 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260518154330/https://github.com/python/cpython/issues/113779
Skip to content
/ cpython Public

Add key argument to tuple.index() #113779

@grigoriev-semyon

Description

@grigoriev-semyon

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()

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions