code for Computer Language Shootout

F. Petitjean littlejohn.75 at news.free.fr
Wed Mar 16 03:24:57 EST 2005


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',
>                               'TGVHCDMKNSYAAWBRTGVHCDMKNSYAAWBR')
> 
> from collections import deque
> from itertools import islice
> 
> 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 in islice(iterseq, linelength) )
	   #  using python 2.4 genexp
> 
> def revcomp(input = sys.stdin):
>      seqlines = deque()
>      for line in input:
>          if line[0] in ">;":
>              output(seqlines)
>              print line,
>              seqlines.clear()
>          else:
>              seqlines.extendleft(line.translate(basetable, "\n\r"))
>      output(seqlines)
> 
> 
> It would be nice to inline the output function, and re-arrange the iteration so 
> that EOF triggers the same suite as line[0] in ">;"
> 
> Michael
> 



More information about the Python-list mailing list