[Tutor] Quick question

Tino Dai tinoloc at gmail.com
Sat Sep 22 18:42:08 CEST 2007


On 9/21/07, Jerry Hill <malaclypse2 at gmail.com> wrote:
>
> On 9/21/07, Tino Dai <tinoloc at gmail.com> wrote:
> > Is there a more pythonic way of doing this:
> >
> >   if queuePacket.has_key('procSeq') and \
> >   queuePacket.has_key('opacSeq') and \
> >   queuePacket.has_key('keySeq') and \
> >   len(queuePacket['procSeq']) == 0 and \
> >   len(queuePacket['opacSeq']) == 0 and \
> >  len(queuePacket['keySeq']) == 0:
>
> Assuming we're talking about Python 2.5 or greater I find the
> following pretty readable:
>
> all(queuePacket.has_key(k) for k in ('procSeq', 'opacSeq', 'keySeq')) and
> \
> all(len(queuePacket[k])==0 for k in ('procSeq', 'opacSeq', 'keySeq'))


You can do that in Python?!?!!! That kicks major a......well, this is a
family list. Thanks for that. I really had no idea that you could do that
kind of syntax structure. Now, I have a bunch of code that I can go and make
a lot shorter and more readable

Thanks,
Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070922/42d3510d/attachment.htm 


More information about the Tutor mailing list