python dict. if statement
python, python-2.7
Solution
sorted(names_states.iteritems(), key=lambda x: (x[1] != 'NY', x[0]))
Problem
Can someone assist me on the proper placement of an if statement on my dict. I am try to flag any user that is NY and have them come first in the dictionary. I am able to get sort by name which I require as well but not clear how to flag any NY users ``` names_states = { 'user1': 'CA', 'user2': 'NY', 'user7': 'CA', 'guest': 'MN', } for key in sorted(names_states.iterkeys()): 2 ... print "%s : %s" %(key, names_states[key]) 3 ... 4 user1 : CA 5 user2 : NY 6 guest : MN 7 user7 : CA ```