python - How can I determine if two values are adjacent in a string? -


(in python 3)

def melting_temperature(dna_sequence, formula): if formula == 'c':     return melting_temperature_count(dna_sequence) else:     modern = melting_temperature_count(dna_sequence)     in len(range(dna_sequence)):         if dna_sequence[i] == 'a' , dna_sequence[i+1] == 't':             modern += modern * 0.01     return modern 

my if statements calculates melting temperature of dna_sequence. in else statement re runs melting_temperature_count (previously defined function) , uses calculated number , adds 1% if 'a' , 't' adjacent in dna_sequence. don't know how compare indices came returning error builtins.typeerror: 'str' object cannot interpreted integer can please tell me how can see if 2 things adjacent? hope explained enough.

you can convert string list , iterate through list comparing adjacent values, like

temp = "string"  lis = list(temp) in range(0, len(lis)-1):     if lis[i] == 'n' , lis[i+1] == 'i' or lis[i] == 'n' , lis[i-1] == 'i':             print "adjacent" 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -