[Tutor] if value in list of dictionaries
Emile van Sebille
emile at fenx.com
Tue Sep 28 17:50:51 CEST 2010
On 9/28/2010 7:12 AM Norman Khine said...
> thanks for the reply, i think i have it now, perhaps it could be done better
>
I think I'd use a helper function to sort:
def sortOtherToEnd(val):
if val['name'] == 'other:
return 'zzzz'
return val['name']
#then sort it
topics.sort(key=sortOtherToEnd)
But, generally, I'd stop once I got it going without worrying too much
about 'better' ways -- that's a subjective measure. There is often one
obvious way to do it, but unless you've seen that way before, there'll
often be many alternatives that work as well.
HTH,
Emile
More information about the Tutor
mailing list