In Python order a dictionary by values and give all keys sharing the lowest value

    # This could be made more efficient.  We want to check quickly "is there
    # any key with a value of 1?" and immediately return when we find one, and
    # if not, then try 2, then 3, and so on.  But we can bail as soon as we
    # find a low integer, without sorting everything; also not known by me if
    # getting a unique set before sorting is faster than not.
    unique = sorted(set(dictionary.values()))
    lowest = unique[0]
    keys = list(filter(lambda x, d=dictionary, val=lowest: d[x] == val, dictionary))

Note that filter takes a function and an iterator to pass through that function (anything that returns True gets included in the resultant output)

And list() just takes the output and converts it from an iterator to a list so you can use it without looping or anything.

Oh, and if you get “TypeError: ’list’ object is not callable” when you try list() then you probably did what i did in my console testing— i assigned a value to list (something like list = ['apple', 'banana', 'rutabaga'] and destroyed my access to the built-in function list(), use del list to restore and of course do not assign things to keywords in your code!

Resources