Re: code for Computer Language Shootout

2005-03-29 Thread igouy
We've made it somewhat easier to contribute programs. No need to subscribe to the mailing-list. No need for a user-id or login. See the FAQ "How can I contribute a program?" http://shootout.alioth.debian.org/faq.php -- http://mail.python.org/mailman/listinfo/python-list

Re: code for Computer Language Shootout

2005-03-18 Thread Bryan
import sys import string def show(seq, table=string.maketrans('ACBDGHK\nMNSRUTWVYacbdghkmnsrutwvy', 'TGVHCDM\nKNSYAAWBRTGVHCDMKNSYAAWBR')): seq = seq.translate(table)[::-1] for i in range(0, len(seq), 60): print seq[i:i+60] couldn't you chang

Re: code for Computer Language Shootout

2005-03-16 Thread Raymond Hettinger
> > . import string, itertools, sys > > . > > . t = string.maketrans('ACBDGHKMNSRUTWVYacbdghkmnsrutwvy', > > . 'TGVHCDMKNSYAAWBRTGVHCDMKNSYAAWBR') > > . > > . for h,b in itertools.groupby( file(sys.argv[1]), lambda x: x[0] in > > ">;" ): > > . if h: > > . print "".j

Re: code for Computer Language Shootout

2005-03-16 Thread Jacob Lee
On Wed, 16 Mar 2005 16:45:53 -0800, bearophileHUGS wrote: > Michael Spencer's version is nice, this is a bit shortened version. The > main() isn't useful for this very short loop, and you can use shorter > variable names to make lines shorter (this code isn't much readable, > it's just for the Sho

Re: code for Computer Language Shootout

2005-03-16 Thread bearophileHUGS
Michael Spencer's version is nice, this is a bit shortened version. The main() isn't useful for this very short loop, and you can use shorter variable names to make lines shorter (this code isn't much readable, it's just for the Shootout, "production quality" code has probably to be more readable.

Re: code for Computer Language Shootout

2005-03-16 Thread Michael Spencer
Steven Bethard wrote: Michael Spencer wrote: def output(seq, linelength = 60): if seq: iterseq = iter(seq) while iterseq: print "".join(islice(iterseq,linelength)) Worth noting: "while iterseq" only works because for this case, you have a list iterator, which provi

RE: code for Computer Language Shootout

2005-03-16 Thread Delaney, Timothy C (Timothy)
Jacob Lee wrote: >> # alias methods to avoid repeated lookup >> join = ''.join I would actually do the alias here sometimes, but give it a semantically-useful name ... nosep_join = ''.join ... Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list

Re: code for Computer Language Shootout

2005-03-16 Thread Steven Bethard
Michael Spencer wrote: def output(seq, linelength = 60): if seq: iterseq = iter(seq) while iterseq: print "".join(islice(iterseq,linelength)) Worth noting: "while iterseq" only works because for this case, you have a list iterator, which provides a __len__ method.

Re: code for Computer Language Shootout

2005-03-16 Thread Michael Spencer
F. Petitjean wrote: Le Tue, 15 Mar 2005 23:21:02 -0800, Michael Spencer a écrit : def output(seq, linelength = 60): if seq: iterseq = iter(seq) while iterseq: print "".join(islice(iterseq,linelength)) I suppose you mean : print "".join( str(item) for item

Re: code for Computer Language Shootout

2005-03-16 Thread Raymond Hettinger
Consider keeping the alias for append because it occurs in the innermost loop. For maximum readability, write: addline = seq.append Move the ''.join() to the show() function. That eliminates a little redundancy. The test dataset doesn't use the semi-colon comment field. So, consider reversin

Re: code for Computer Language Shootout

2005-03-16 Thread F. Petitjean
Le Tue, 15 Mar 2005 23:21:02 -0800, Michael Spencer a écrit : > Jacob Lee wrote: >> On Tue, 15 Mar 2005 21:38:48 -0800, Michael Spencer wrote: >> >> Good call. >> >> > > How about this then: > > basetable = string.maketrans('ACBDGHKMNSRUTWVYacbdghkmnsrutwvy', > 'T

Re: code for Computer Language Shootout

2005-03-15 Thread Michael Spencer
Jacob Lee wrote: On Tue, 15 Mar 2005 21:38:48 -0800, Michael Spencer wrote: string.translate is a good idea. Note you can handle upper-casing and translation in one operation by adding a mapping from lower case to the complement i.e., table = string.maketrans('ACBDGHK\nMNSRUTWVYacbdghkmnsrutwvy',

Re: code for Computer Language Shootout

2005-03-15 Thread Steven Bethard
Jacob Lee wrote: So here's a tentative contest version of the code: import sys import string def show(seq, table=string.maketrans('ACBDGHK\nMNSRUTWVYacbdghkmnsrutwvy', 'TGVHCDM\nKNSYAAWBRTGVHCDMKNSYAAWBR')): seq = seq.translate(table)[::-1] for i in ra

Re: code for Computer Language Shootout

2005-03-15 Thread Jacob Lee
On Tue, 15 Mar 2005 22:45:48 -0700, Steven Bethard wrote: > # table as default argument value so you don't have to do > # a global lookup each time it's used > > def show(seq, table=string.maketrans('ACBDGHK\nMNSRUTWVY', > 'TGVHCDM\nKNSYAAWBR') > seq = s

Re: code for Computer Language Shootout

2005-03-15 Thread Jacob Lee
On Tue, 15 Mar 2005 21:38:48 -0800, Michael Spencer wrote: > string.translate is a good idea. Note you can handle upper-casing and > translation in one operation by adding a mapping from lower case to the > complement i.e., > > table = string.maketrans('ACBDGHK\nMNSRUTWVYacbdghkmnsrutwvy', >

Re: code for Computer Language Shootout

2005-03-15 Thread Steven Bethard
Jacob Lee wrote: There are a bunch of new tests up at shootout.alioth.debian.org for which Python does not yet have code. I've taken a crack at one of them, a task to print the reverse complement of a gene transcription. Since there are a lot of minds on this newsgroup that are much better at optim

Re: code for Computer Language Shootout

2005-03-15 Thread Robert Kern
Here's my solution to the problem[1]: [1] http://shootout.alioth.debian.org/benchmark.php?test=revcomp import sys import string basetable = string.maketrans('ACBDGHKMNSRUTWVYacbdghkmnsrutwvy', 'TGVHCDMKNSYAAWBRTGVHCDMKNSYAAWBR') def revcomp(seqlines, linelength=60, base

Re: code for Computer Language Shootout

2005-03-15 Thread Michael Spencer
Jacob Lee wrote: There are a bunch of new tests up at shootout.alioth.debian.org for which Python does not yet have code. I've taken a crack at one of them, a task to print the reverse complement of a gene transcription. Since there are a lot of minds on this newsgroup that are much better at optim

Re: code for Computer Language Shootout

2005-03-15 Thread Robert Kern
Jacob Lee wrote: By the way - is there a good way to find out the maximum memory a program used (in the manner of the "time" command)? Other than downloading and running the shootout benchmark scripts, of course. Inserting appropriate pauses with raw_input() and recording the memory usage using to

code for Computer Language Shootout

2005-03-15 Thread Jacob Lee
There are a bunch of new tests up at shootout.alioth.debian.org for which Python does not yet have code. I've taken a crack at one of them, a task to print the reverse complement of a gene transcription. Since there are a lot of minds on this newsgroup that are much better at optimization than I, I