I am trying to write a function that takes two string arguments and returns the number of times a character from the first line appears in the second line.
I am a complete newbie in python and in a dead end. If someone could point me in the right direction, that would be great. I was given this to start with:
def occurrences(text1, text2): """Return the number of times characters from text1 occur in text2 occurrences(string, string) -> int """
As you can see, 2 lines are needed. I thought line 1 and line 2 would be sufficient, but I do not know how to define them.
I started from this until now, and I have not even succeeded.
for c in "string": print c if c == char c in "string2": count += 1
I am just throwing random variables, because how can I find char (AZ) in a string that I don't even know?
EDIT: some of the tips you guys told me I haven't learned yet. For this question, I should use:
I was also given some tips:
Tip 1. You may find in useful for testing if one line is on the other line.
Hint 2. Look at each character in the second argument and see if it is in the first argument.
source share