On Sep 11, 10:36 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
>I'd type the explicit
>
>  v1,v2,v3 = mydict['one'], mydict['two'], mydict['two'] # 54 chars > Either 
> is only a couple more
> characters to  type.  It is completely
> explicit and comprehensible to everyone, in comparison to
>
>   v1,v2,v3 = [ mydict[k] for k in ['one','two','two']] # 52 chars
>   v1,v2,v3 = [ mydict[k] for k in 'one two two'.split()] # 54 chars
>
> Unlike perl, it will also blow up if mydict doesn't contain 'one'
> which may or may not be what you want.
>

Is your above solution robust against undefined keys.
In my example it would'nt be a problem. The dict would be fully
populated, but I'm just curious.


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to