In: Computer Science
Write a function that takes a person’s first and last names as input and
(a) uses lists to return a list of the common letters in the first and last names (the intersection).
(b) uses sets to return a set that is the intersection of the characters in the first and last
names.
(c) uses sets to return the set that is the symmetric difference between the first and last
names.
please write in python program
a.
import string
def getcommonletters(text1, text2);
"""Take two strings and a return a list of letters common to both strings."""
text1List = text1.split()
text2List = text2.split()
for i in range(0, len(text1List));
text1List[i] = getCleanText(text1list[i])
for in range (0, len(text2List));
text2List[i] = getCleanText(text2list[i])
outList = []
for letter in text1list:
if letter in text2list and letter not in outList:
outList.append(letter)
return outList
def getCleanText(text):
"""Return letter in lower case stripped of whitespace and punctuation characters."""
text = text.lower()
bad characters = string.whitespace + string.punctuation
for character in bad characters:
text = text.replace (character, "")
return text
userText1 = raw_input ("Enter your first name:")
userText2 = raw_input ("Enter your last name:")
result = getCommonLetters(userText1, userText2)
numMatches = len(result)
if numMatches == 0:
print "No Matches."
else:
print "Number of Matches:", numMatches
for letter in result:
print letter