On 2014-02-08 19:29, Chris Angelico wrote: > On Sat, Feb 8, 2014 at 7:25 PM, Igor Korot <ikoro...@gmail.com> > wrote: > >> Try this: > >> > >> sorted_items = sorted(my_dict.keys(), key=my_dict.get) > > > > This code fail. > > Actually, it's a list of keys - notice that I changed > my_dict.items() into my_dict.keys()?
Unless you need to make a copy (for purposes of altering the original while iterating), that's the default behavior of iterating over a dict, so it could be simplified to sorted_items = sorted(my_dict, key=my_dict.get) -tkc -- https://mail.python.org/mailman/listinfo/python-list