Question

In: Computer Science

Write a function that takes a person’s first and last names as input and (a) uses...

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

Solutions

Expert Solution

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

Related Solutions

In R studio Write a function that takes as an input a positive integer and uses...
In R studio Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Use the lapply function, do not use any of the loop commands in your code.
Write a function that takes a number as input, and returns the character A if the...
Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab...
Write code to read a list of song names and durations from input. Input first receives...
Write code to read a list of song names and durations from input. Input first receives a song name, then the duration of that song. Input example: Time 424 Money 383 quit. #include <iostream> #include <string> #include <vector> using namespace std; class Song { public: void SetNameAndDuration(string songName, int songDuration) { name = songName; duration = songDuration; } void PrintSong() const { cout << name << " - " << duration << endl; } string GetName() const { return name;...
write a function that takes as input the root of a general tree and returns a...
write a function that takes as input the root of a general tree and returns a binary tree generated by the conversion process illustrated in java
Write a function that takes a C string as an input parameter and reverses the string.
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
in c++ Write a function that takes a C string as an input parameter and reverses...
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
Write an R function that conducts a normality test as follows: it takes as input a...
Write an R function that conducts a normality test as follows: it takes as input a data set, calculates a bootstrap confidence interval for the skewness, calculates a bootstrap confidence interval for the kurtosis, then sees if 0 is in the skewness interval and 3 is in the kurtosis interval. If so, your routine prints that the data is normally distributed, otherwise your routine should print that the data is not normally distributed. Test your routine on random data from...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or any vector and simply returns back the transpose of that input. You can always verify your answer by using the inbuilt transpose function in MATLAB, however, you cannot use the transpose function directly when writing your code. Here is the starter code that we are providing to help you get started %x is the input vector or matrix. You can find the %size that...
USING PYTHON, write a function that takes a list of integers as input and returns a...
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]. DO NOT use any special or built in functions like append, reverse etc.
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal matrix given as two vectors: n×1 vector v representing the main diagonal and (n−1)×1 vector w representing the upper diagonal. Have this function output the Cholesky factor of the matrix as a vector for the main diagonal and a vector for the upper diagonal and output the number of flops and, separately, the number of square roots used as well. Use only basic programming....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT