2. Write a function num_diff(s1, s2) that takes as inputs two strings s1 and s2 (which you can assume have the same length) and returns the number of differences between the two strings i.e., the number of positions at which the two strings have different characters. For example:
>>> num_diff('alien', 'allen') # only position 2 is different
>>> num_diff('alien', 'alone') # the last 3 positions all differ
>>> num_diff('same', 'same') # no differences!
3. Write a function index(elem, seq) that takes as inputs an element elem and a sequence seq and returns the index of the first occurrence of elem in seq. The sequence seq can be either a list or a string. If seq is a string, elem will be a single-character string; if seq is a list, elem can be any value. If elem is not an element of seq, the function should return the length of the sequence. Dont forget that the index of the first element in a sequence is 0. Here are some examples:
>>> index(5, [4, 10, 5, 3, 7, 5])
>>> index('a', 'banana')
>>> index('i', 'team')
>>> index('hi', ['hello', 111, True])
>>> index('hi', ['well', 'hi', 'there'])
>>> index('a', '') # the empty string
>>> index(42, ) # the empty list
if elem not in seq:
DNA transcription! The last two functions are based on an incredible molecular feat called transcription, in which your cells create molecules of messenger RNA that mirror the sequence of nucleotides in your DNA. The RNA is then used to create proteins that do the work of the cell.
4. Write a function called one_dna_to_rna(c) that takes as input a single-character string c representing a DNA nucleotide and returns the corresponding messenger-RNA nucleotide. Here are the DNA-to-RNA conversions:
‘A’ in DNA becomes ‘U’ in RNA.
‘C’ in DNA becomes ‘G’ in RNA.
‘G’ in DNA becomes ‘C’ in RNA.
‘T’ in DNA becomes ‘A’ in RNA.
Any other input should produce an output of the empty string (''). This function does not require recursion.
Here are some examples:
5. Write a function called transcribe(s) that takes as input a string s representing a piece of DNA, and returns a string representing the corresponding RNA. Any characters in the input that dont correspond to a DNA nucleotide should not appear in the returned RNA string. (Note that if you implemented the previous function correctly, you shouldnt need to do anything special here to ensure that non-DNA characters are removed.) For example:
>>> transcribe('ACGT TGCA')
>>> transcribe('cs111') # lower-case letters don't count
Use your one_dna_to_rna function and recursion to solve this problem. As with the scrabble_score function, you may find it helpful to use the num_vowels function from lecture as a model, but in this case you will be adding together strings instead of numbers!