I tried trying my approach but not getting the result required and keep getting the error: “String indices must be integers”
def common_letters(string_one, string_two):
#List to hold common characters
for char in string_one:
#comparing if character exist in both
if(string_one[char] in string_two):
#Adding common character in str
These are two separate functions
def contains and
def common_letters. Which one are you having an issue with?
Sorry must have pasted all.
Referring to the deff common_letters
Based on the error code it sounds like you’ve attempted to index a string using another string. Like lists indexing by element (character) for a string should be integer numbers-
name = "bob"
Have a look in your code for any instances where you might’ve passed a type you didn’t mean to.
For future posts could you please format the code- How do I format code in my posts? as it’s much easier for others to read .