recombination variations

Scott David Daniels Scott.Daniels at Acm.Org
Thu Dec 2 15:07:05 EST 2004


Hung Jung Lu wrote:
> ... expand = lambda t: reduce(lambda r, s: [x+y for x in r 
 >                                for y in alphabet[s]], t, [''])
> print expand('ATSGS')

Or, for a more verbose version:

     multis = dict(W='AT', M='AC', R='AG', Y='TC', K='TG', S='CG',
                   H='ATC', D='ATG', V='AGC', B='CTG', N='ATCG')

     def expanded(string, expansions=multis):
         result = ''
         for pos, char in enumerate(string):
             if char in multis:
                 break
         else:
             yield string
             raise StopIteration
         parts = multis[char]
         prelude, string = string[:pos], string[pos+1:]
         for expansion in expanded(string, multis):
             for middle in parts:
                 yield prelude + middle + expansion


--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list