0

Given the dictionary below, I tried to sort it by the value order 0,1,2,3,4 without any success

items = {
            'Customer'          : ['Form', 'Customer is module for recording information.', 0], 
            'Age'               : ['Label', 'This field for input Age of Customer automatically calculated by system against date of birth.', 4], 
            'Salutation'        : ['Label', 'A greeting in words or actions or the words used at the beginning of a letter or speech.', 2], 
            'As a Guarantor'    : ['Label', 'Whether or not a customer is a guarantor to another customer.', 1], 
            'First Name English': ['Label', 'The name that was given to you when you were born and that comes before your family name.', 3]
        }

print "before sort dictionary"
print items

items    = dict(sorted(items.items(),key=lambda (k,v):int(v[2]))) # Sort Dictionary By key/value 'Order'
print "after sort dictionary"
print items

After sorted(), the dictionary slightly changed but still not correctly, the item after sorted is as this:

{
    'Customer'          : ['Form', 'Customer is module for recording information.', 0], 
    'As a Guarantor'    : ['Label', 'Whether or not a customer is a guarantor to another customer.', 1], 
    'Age'               : ['Label', 'This field for input Age of Customer automatically calculated by system against date of birth.', 4], 
    'Salutation'        : ['Label', 'A greeting in words or actions or the words used at the beginning of a letter or speech.', 2], 
    'First Name English': ['Label', 'The name that was given to you when you were born and that comes before your family name.', 3]
}

Please kindly help how can sort this dictionary correctly? Thanks

Houy Narun
  • 1,557
  • 5
  • 37
  • 86

0 Answers0