Write a function called
common_lettersthat takes two arguments,
string_twoand then returns a list with all of the letters they have in common.
The letters in the returned list should be unique.
I already wrote this code for a previous question to check whether a string is within another string:
def contains(big_string, little_string): if little_string in big_string: return True else: return False
For the question I copy pasted here, I used this code:
def common_letters(string_one, string_two): group1 =  group2 =  alphabets = "abcdefghijklmnopqrstuvwxyz" for a in alphabets: for c1 in string_one: if a == c1: group1.append(a) break for c2 in string_two: if a == c2: group2.append(a) break common =  for g1 in group1: for g2 in group2: if g1 == g2: common.append(g1) return common
When I pressed run, I got this response:
Expected the test common_letters(‘python’, ‘ruby on rails’) to return [‘y’, ‘o’, ‘n’], instead got [‘n’, ‘o’, ‘y’]
My question is, does the sequence really matter?
And to be honest, I didn’t really know why my code worked…
It’s my first time posting a question, I wonder if the format is ok.