I know that I’ve tried to solve it differently by going at it differently and not using “in” for both parameters and I’ve understood how to answer the question.
However, I’m having trouble understanding why the code I’ve written always seems to be returning an empty list.
def common_letters(string_one, string_two):
common_lst = []
for char1 in string_one:
for char2 in string_two:
if char1 == char2 and char1 not in common_lst == True:
common_lst.append(char1)
return common_lst
**Edit:
I’ve also tried changing the indentation of the return common_lst with no avail. So far I understand the concepts taught in this course pretty well, but for some reason I always struggle with indentation!
Is it really necessary to iterate both strings? Consider that in is a sort of iterator as it seeks membership. Iterating over one string (either one) and searching in the other will certainly detect any matches.
Woah. Took me a good minute to see that there was comparison chaining there even after you said it. That’s pretty surprising. I’d never write that, but I’d also never spot it by only reading it.