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):
  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)

What specific parts of the code do you not understand?

Do you know how a for loop works in Python?

Do you understand how if statements work in Python?

Do you understand what lists are in Python and how to add items to them?

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

Sounds like you need to work though a Basic Python course first, to learn about the various syntax that is presented in the code above. We do not currently have such a course, but one is being developed and will launch in the not so distant future.

1 Like

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)!