Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add key argument to tuple.index() #113779

Closed
grigoriev-semyon opened this issue Jan 6, 2024 · 3 comments
Closed

Add key argument to tuple.index() #113779

grigoriev-semyon opened this issue Jan 6, 2024 · 3 comments
Labels
type-feature A feature request or enhancement

Comments

@grigoriev-semyon
Copy link
Contributor

grigoriev-semyon commented Jan 6, 2024

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

@grigoriev-semyon grigoriev-semyon added the type-feature A feature request or enhancement label Jan 6, 2024
@grigoriev-semyon grigoriev-semyon changed the title Add key argument to tuple.index() Add key argument to tuple.index() Jan 6, 2024
@ericvsmith
Copy link
Member

Please open a discussion at https://discuss.python.org/c/ideas/6.

@grigoriev-semyon
Copy link
Contributor Author

@hauntsaninja
Copy link
Contributor

There's more discussion over at #113773. I'm going to close this as a duplicate (most of the discussion points are the same / if it's added to list it should be added to tuple / overall I think we're unlikely to add this)

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants