Hello,could somebody explain all the steps due to which code works like this?I am kettle
Write a function called common_letters that takes two arguments, string_one and string_two and then returns a list with all of the letters they have in common.
The letters in the returned list should be unique. For example,
common_letters(“banana”, “cream”)
should return ['a'] .
def common_letters(string_one, string_two):
common = []
for letter in string_one:
if (letter in string_two) and not (letter in common):
common.append(letter)
return common
I am doing a course at Python now can not fully describe the part I do not understand(The thing is in this part of code
for letter in string_one:
if (letter in string_two) and not (letter in common):
do not understand why do we compare string_two and letter in common if common list is blank.Won`t it add all letters from string two into blank list?While we need to get common letters from string 2 and string1
it is checking that the letter is not already included in common (note it is using and not), if it is already in common then it is not necessary to add it again