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

Builtin min() does not support argument key #422

Open
akleemans opened this issue Jul 15, 2023 · 5 comments
Open

Builtin min() does not support argument key #422

akleemans opened this issue Jul 15, 2023 · 5 comments
Assignees
Labels
bug Something isn't working stdlib Standard library feature

Comments

@akleemans
Copy link

I have the following code:

distances = {'a': 4, 'b': 1}
queue = ['a', 'b']
u = min(queue, key=distances.get)
queue.remove(u)
print(queue)

When run with Python 3.11.1, I get the expected result printed:

> python3 min_example.py
['a']

If I try to run it with Codon 0.16.2, I get the following:

> codon run min_example.py 
min_example.py:3:20-33: error: 'key' is an invalid keyword argument for min()

Is this expected? I assumed the key parameter would be supported for min().

@arshajii
Copy link
Contributor

Thanks for the report -- yes we definitely should support that. We'll plan to have it in the next release!

@akleemans
Copy link
Author

Awesome, thanks very much!

@inumanag inumanag self-assigned this Jul 26, 2023
@inumanag inumanag added bug Something isn't working stdlib Standard library feature labels Jul 26, 2023
@akleemans
Copy link
Author

By the way, this is also the case for max().
For example, for finding the most common letter in letters, this is a short way of writing it:
most_common = max(set(letters), key=letters.count)

Unfortunately this still throws an error in Codon 0.16.3:
error: 'key' is an invalid keyword argument for max()

@arshajii
Copy link
Contributor

arshajii commented Dec 7, 2023

Hi @akleemans, I've created a PR for this here: #505 -- it'll be included in the next version that we plan to release in the next couple weeks!

@akleemans
Copy link
Author

Awesome, appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stdlib Standard library feature
Projects
None yet
Development

No branches or pull requests

3 participants