How do I count the number of identical characters in a string by position using python? -


for example:

string 1: aggcct           || | | string 2: agccat 

these 2 strings identical @ 4 positions, function want return 4.

is there clever (i.e., fast) method doing this, other obvious method of iterating through both strings @ same time?

thanks! uri

i don't think "clever" trick beats obvious approach, if it's executed:

sum(c1 == c2 c1, c2 in itertools.izip(s1, s2)) 

or, if use of booleans arithmetic irks you,

sum(1 c1, c2 in itertools.izip(s1, s2) if c1 == c2) 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -