I'm trying to write a function that takes two string arguments and returns the number of times a character from the first string occurs in the second string.
I am a complete beginner to python and am stumped. If anyone could point me in the right direction that would be great. I've been given this to start with:
def occurrences(text1, text2):
"""Return the number of times characters from text1 occur in text2
occurrences(string, string) -> int
"""
#Your code goes here
As you can see, 2 strings are needed. I thought that string 1 and string 2 would be sufficient but I have no idea how to to define them.
I have started with this so far and I'm not even having any success.
for c in "string":
print c
if c == char c in "string2":
count += 1
I'm just throwing in random variables because how am I suppose to find char(A-Z) in a string that I dont even know?
EDIT: some of the tips you guys have told me i havn't learned yet. For this question i should be using:
- for loop
in
Some hints were given to me also:
Hint 1: You might find in
useful for testing if one string is in another string.
Hint 2: Look at each character in the second argument and see if it is in the first argument.