Ready code which don`t know why works so.(Python beginner function

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

Did you write the code? Can you explain your process in creating it?

not me,that is why I am asking whether smb could explain the ethaps(steps of it)

know only about lists(The first two paragraphs are OK for me

This is a pretty useful video made by Free Code Camp. I just started learning Python.

1 Like

Welcome back, @sbfx. That Python video is one of our most popular videos. I’m glad to hear you’re finding it helpful.

Ok,thank you,sbfx)?-!

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

how does Python get that those letters that don`t repeat should not be included into common?

it is the condition you quoted before
it says (in pseudo-code)

for each letter in string_one
   if letter is included in string_two but not in common
    then append it to common
  otherwise do nothing 
1 Like

OK!Finally got it!Thank you very much.A bit stuck on this place

I suggest you review loops, logic operators, if statements and how in works

1 Like

Okay,thank you for help)!