azalea says

Don't do things the hardest way

Given a DNA sequence, say DNA = ‘AATTGGCCA’, count how many times a given nucleotide (e.g. ‘A’) appears.

I used to do this in Python:

>>>DNA = 'AATTGGCCA'
>>> len(filter(lambda x: x=='A',DNA))
3

Today, I just find out I can simply do:

>>> DNA.count('A')
3

Feel silly myself, but begin to love Python even more!

programming python · Tweet Edit