On Tue, Nov 24, 2015 at 9:04 PM, Cai Gengyang <gengyang...@gmail.com> wrote: > Here's a dictionary with 3 values : > > results = { > "gengyang": 14, > "ensheng": 13, > "jordan": 12 > } > > How do I define a function that takes the last of the 3 items in that list > and returns Jordan's results i.e. (12) ? > > Thanks a lot !
If you want Jordan's result, that's easy: result["jordan"] But there's no concept of "the last" entry in a dict. They don't have an order. Do you mean "the entry with the greatest key"? That could be written thus: result[max(result)] because max(result) is the string "jordan". Does either of those make sense for what you're doing? ChrisA -- https://mail.python.org/mailman/listinfo/python-list