This the question: Make a function that takes two strings as input, and print the common letters that they share. The printed letters should: - be lowercase - be in alphabetical order - appear as a single string. Please see the example to see the format of the string - There should only be letters in your result, no whitespace, numbers or special characters and if no common letter is found print no common letters.
Example usage: task("House","computers") should print e, o, s and u exactly. If it prints eosu then that would be incorrect. task("Hi","there") should print h task("Foo","bar") should print no common letters There should only be one call to print.
This is the problem I'm encountering: The below code when run prints no common letters but I used to get feedback from a bot that the task should print (and not return) a string. Please just use one print statement. E.g: task('I like big cups!','and I cannot lie!') should call print('c, e, i and l). Please help me check whether there is an arrangement problem or help me modify the code.
badchars = ['$','@','%',';',':','!',"*"," ",'1',"2","3","4","5","6","7","8","9","0",'^','&','#','~','?','[]','{',']',"+",'=','-','_','-',",",'"',"'",'`',"|","\\",'(',')']
def task(str1, str2):
str1=str1.casefold()
str2=str2.casefold()
for letter in badchars:
str1=str1.replace(letter,"")
str2=str2.replace(letter,"")
common =(list(set(letter for letter in str1 if letter in str2)))
letter=len(common)
if letter>1:
common.insert(-1,"and")
common= ','.join(common)
common = common.replace(',and,', ' and ')
if letter==0:
common='no common letters'
print(f'{common}')
task("foo", "bar")