[Tutor] dictionary values
Brian van den Broek
bvande at po-box.mcgill.ca
Sat Jul 9 02:56:45 CEST 2005
Don Parris said unto the world upon 08/07/2005 20:09:
> On 7/8/05, luke p <rabidpoobear at gmail.com> wrote:
>>what I want to do is find out which value in my dictionary is lowest.
>>is there a dictionary function for this, like alpha.min() that will
>>return a key:value pair of the lowest? I cannot find one and I
>>wondered if there was a quick fix to this.
>>thanks in advance.
> I'm new at this, but thought I would throw my $0.02 in the ring for
> the learning experience. I know that sequence operations won't work
> on dictionaries. I wonder if you could get away with a lambda here?
> I'm probably in way over my head, but would something like this work:
> min = (lambda x, y: x < y)
> min(1, 9)
> Could min() take the dictionary values, as in min(dict, dict)?
> Again, I'm no expert, but having my input picked apart will be a good thing. ;)
try it out at the prompt :-)
>>> min = (lambda x, y: x < y)
>>> min(1, 9)
So, that's just a complicated way of saying x < y. ;-)
There is also a bit of a consensus (though not unanimous) that using
lambda to get a function bound to a name is to obscure a def. (See
More information about the Tutor