0

I'm attempting to reorder the values of a particular key in a python dictionary.

For instance, if a I have dictionary {'a':"hello","hey","hi"}

When i print the values of 'a', how could I change the order of "hello", "hey", or "hi"?

alexizydorczyk
  • 850
  • 1
  • 6
  • 25

1 Answers1

0

To rephrase this: the value of your key 'a' in your dictionary is a list containing 3 string-objects.

dict = { 'a': [ "hello", "hey", "hi" ] }

this being the case, you can sort the list like this

Community
  • 1
  • 1
supertopi
  • 3,469
  • 26
  • 38
  • Thank you, although, I am attempted to sort by the order that they were added to the dictionary, is this still possible with sort()? – alexizydorczyk Feb 04 '12 at 22:41
  • It's hard to say without seeing some code, but I think a list might maintain the chronological order automatically (just a guess). – supertopi Feb 04 '12 at 22:45