sort a dictionary by keys in specific order

Paul Rubin http
Fri May 26 19:36:12 CEST 2006


"spohle" <spohle at gmail.com> writes:
> dic = {'key1':'value1', 'key2':'value2', 'key3':'value3'}
> 
> list = [key2, key3, key1]

Is this what you want?

    dic = {'key1':'value1', 'key2':'value2', 'key3':'value3'}
    keys = ['key2', 'key3', 'key1']
    items = [dic[k] for k in keys]
    print items



More information about the Python-list mailing list