[Tutor] if value in list of dictionaries

Norman Khine norman at khine.net
Tue Sep 28 18:37:09 CEST 2010


thank you, here is the updated version:

http://pastie.org/1186860

On Tue, Sep 28, 2010 at 5:50 PM, Emile van Sebille <emile at fenx.com> wrote:
> 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
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
˙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