Write a function
printCommonLetters()
that has two input arguments:
lst1
andlst2
, which are two lists of strings.
The function will print the items that are the same in both lists.
When you are done iterating over both loops, print a final statement like ‘done’ or ‘goodbye’.We discussed in class how execution resumes with non-indented statement that is aligned with for in the for loop statement.
For example if
lst1 = [ ‘ab’, ‘cd’, ‘ef’, ‘gh’]
lst2 = [‘abc’, ’geh’, ‘cd’, ‘ab’],
the function will print:
‘ab’
‘cd’
‘goodbye!’
I have found shorthanded way to do it, but not a full function. I have it giving me back ['ab', 'abc']
, but cant get it to give me the 'cd'
...
here is what I have so far:
def printCommonLetters( lst1, lst2):
for i in lst1:
for j in lst2:
if i is not j:
return[i,j]
print( printCommonLetters( [ 'ab', 'cd', 'ef', 'gh'],['abc', 'geh', 'cd', 'ab'] ))
print('goodbye!')