codon icon indicating copy to clipboard operation
codon copied to clipboard

Builtin `min()` does not support argument `key`

Open akleemans opened this issue 2 years ago • 5 comments

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

akleemans avatar Jul 15 '23 13:07 akleemans

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

arshajii avatar Jul 18 '23 12:07 arshajii

Awesome, thanks very much!

akleemans avatar Jul 18 '23 13:07 akleemans

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

akleemans avatar Dec 07 '23 20:12 akleemans

Hi @akleemans, I've created a PR for this here: https://github.com/exaloop/codon/pull/505 -- it'll be included in the next version that we plan to release in the next couple weeks!

arshajii avatar Dec 07 '23 20:12 arshajii

Awesome, appreciate it!

akleemans avatar Dec 08 '23 08:12 akleemans

I see PR #505 was merged and this issue can be closed now.

avitkauskas avatar Aug 28 '24 21:08 avitkauskas

As @avitkauskas pointed out, this has been merged, closing.

akleemans avatar Aug 29 '24 12:08 akleemans