Light Mode
Dark Mode
Dealing with "key"

I cannot solve this.

min([1, 2, 3], [5, 6], [7], [0, 0, 0, 10], key=sum)

My code for that is here.

key = kwargs.get("key", None)
if key:
    for n in sort_source:
        if key(n)<min: min=n

Although, it works with,

    min([[1, 2], [3, 4], [9, 0]], key=lambda x: x[1])

Then I tried following this, but it didn't work.

    if key == "lambda":
    elif key == "sum":


When I use "print", it shows

    key: <function <lambda> at 0x25f9cf8>

What should I do for this? If you give me some pieces of advice, I would appreciate.

Thanks.

Created: Nov. 14, 2015, 5:09 p.m.
Updated: Nov. 16, 2015, 10:53 a.m.
1
16
User avatar
nanpa