python - Creating a new list with elements taken out -


so i'm trying pull off in python program enter dna sequence bases mixed other extraneous characters, , have output of strand bases, in caps. code i've been working on far - new python, i'm not sure why program isn't working. if give me pointers on should add here make code work, great.

class dnastring (str):     def __new__(self,s):         return str.__new__(self,s.upper())     def bases (list):         bases = [a,c,t,g]      def newstrand (self):         newstrand = [self]         newstrand = [x x in newstrand if x not a]         newstrand = [x x in newstrand if x not c]         newstrand = [x x in newstrand if x not t]         newstrand = [x x in newstrand if x not g]         return (newstrand)      def printnewstrand (self):         print ("new dna strand: {0}".format(self.newstrand()))  dna = input("enter dna sequence: ") x=dnastring(dna) x.newstrand() 

a single function need. 1 uses generator expression instead of filter , lambda result same.

>>> def strand(base="actg"): ...     """ return strand user input """ ...     s = raw_input("enter sequence: ") ...     return "".join(x x in s.lower() if x in base.lower()).upper() ...  >>> strand() enter sequence: asdffeeakttycasdgeadc 'aattcagac' 

another example:

>>> strand() enter sequence: asdfsdf29038520395slkdgjw3l4ktjnd,cvmbncv,bhieruoykrjghcxvb 'agtccgc 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -