[Tutor] Optimisation of prime number program (cont. from finding prime numbers)

2007-09-21 Thread Boykie Mackay
Ok,I have learnt how to generate prime numbers and how to 'split' input.The above was to help me solve the second 'SPOJ' challenge,PRIME1.The challenge can be found at I have written my solution and tested it and it works fine,but unfortunat

Re: [Tutor] Optimisation of prime number program (cont. from finding prime numbers)

2007-09-21 Thread Kent Johnson
Boykie Mackay wrote: > Ok,I have learnt how to generate prime numbers and how to 'split' > input.The above was to help me solve the second 'SPOJ' > challenge,PRIME1.The challenge can be found at > > > I have written my solution and tested it

Re: [Tutor] Optimisation of prime number program (cont. from finding prime numbers)

2007-09-21 Thread Eric Brunson
Boykie Mackay wrote: > Ok,I have learnt how to generate prime numbers and how to 'split' > input.The above was to help me solve the second 'SPOJ' > challenge,PRIME1.The challenge can be found at > > > I have written my solution and tested it

[Tutor] Fwd: Optimisation of prime number program (cont. from finding prime numbers)

2007-09-21 Thread Kalle Svensson
Oops, forgot to send to the list. Hi! On 9/21/07, Boykie Mackay <[EMAIL PROTECTED]> wrote: > Ok,I have learnt how to generate prime numbers and how to 'split' > input.The above was to help me solve the second 'SPOJ' > challenge,PRIME1.The challenge can be found at >

[Tutor] Quick question

2007-09-21 Thread Tino Dai
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: ? -Thanks, Tino

Re: [Tutor] Quick question

2007-09-21 Thread Kent Johnson
Tino Dai 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['key

Re: [Tutor] Quick question

2007-09-21 Thread Michael Langford
Use the .get method of the dict to return a nonzero value (say None or -1) when it can't find an item. That will half your test cases. Example of .get below: --Michael >>> foo = {} >>> foo['d']=0 >>> foo['a']=1 >>> if(foo.get('a',1)==0 and foo.get('q',1)==0): print foo ... else: print "adsfl

Re: [Tutor] Quick question

2007-09-21 Thread Eric Brunson
There are quite a few ways to do what you want. Here's are a few variations on a theme: try: if not any( ( len(queuePacket['procSeq']), len(queuePacket['opacSeq']), len(queuePacket['keySeq']) ) ): # Do your stuff here do_stuff() except KeyE

Re: [Tutor] Quick question

2007-09-21 Thread Jerry Hill
On 9/21/07, Tino Dai <[EMAIL PROTECTED]> 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']) ==