[Tutor] adding dictionary value at position [-1]
Norman Khine
norman at khine.net
Sat Aug 6 13:32:17 CEST 2011
hello,
i know that there are no indexes/positions in a python dictionary,
what will be the most appropriate way to do this:
addresses = {}
for result in results.get_documents():
addresses[result.name] = result.title
# we add a create new address option, this needs to be
the last value
addresses['create-new-address'] = 'Create new address!'
# {"address-one": "Address One", "create-new-address":
"Create new address!", "address-two": "Address Two"}
return dumps(addresses)
so that when i return the 'dumps(addresses)', i would like the
'create-new-address' to be always at the last position.
any advise much appreciated.
norman
--
˙ʇı ɹoɟ ƃuıʎɐd ǝɹ,noʎ ʍou puɐ ǝɔıoɥɔ ɐ ʞooʇ ı ʇɐɥʇ sı 'ʇlnɔıɟɟıp sı ʇɐɥʍ
˙uʍop ǝpısdn p,uɹnʇ pןɹoʍ ǝɥʇ ǝǝs noʎ 'ʇuǝɯɐן sǝɯıʇ ǝɥʇ puɐ 'ʇuǝʇuoɔ
ǝq s,ʇǝן ʇǝʎ
%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )
More information about the Tutor
mailing list