Question

In python,write a function nameSet(first, last) that takes a person's first and last names as input,...

In python,write a function nameSet(first, last) that takes a person's first and last names as input, and returns a tuple of three strings: the first string gives the union of all letters in the first and last names (no duplication though). The second string gives the intersection of letters in the first and last names, i.e. the common letters. If there are no common letters, then the second string is empty (''). The third string gives the symmetric difference between the first and last names, i.e., letters that only appear in one name but not the other name. Letters in the three strings should be sorted alphabetically. Ignore case. Example: nameSet('George', 'Washington') will return ('aeghinorstw', 'go', 'aehinrstw').

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def nameSet(first, last):
    setF = set(first.lower())
    setL = set(last.lower())
    result1 = list(setF.union(setL))
    result2 = list(setF.intersection(setL))
    result3 = list(setF.symmetric_difference(setL))
    result1.sort()
    result2.sort()
    result3.sort()
    res1 = ''.join([str(x) for x in result1])
    res2 = ''.join([str(x) for x in result2])
    res3 = ''.join([str(x) for x in result3])
    return (res1, res2, res3)


# Testing
print(nameSet('George', 'Washington'))

Add a comment
Know the answer?
Add Answer to:
In python,write a function nameSet(first, last) that takes a person's first and last names as input,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python 3.7.3 ''' Problem 3 Write a function called names, which takes a list of strings...

    Python 3.7.3 ''' Problem 3 Write a function called names, which takes a list of strings as a parameter. The strings are intended to represent a person's first and last name (with a blank in between). Assume the last names are unique. The function should return a dictionary (dict) whose keys are the people's last names, and whose values are their first names. For example: >>> dictionary = names([ 'Ljubomir Perkovic', \ 'Amber Settle', 'Steve Jost']) >>> dictionary['Settle'] 'Amber' >>>...

  • Write a program that reads a person's first and last names, separated by a space. Then...

    Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is: Maya Jones Jones, Maya import java.util.Scanner; public class SpaceReplace {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       String firstName;       String lastName; //answer goes here//    } }

  • Write a program that reads a person's first and last names, separated by a space. Then...

    Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is Maya Jones Tones, Maya import java . util·Scanner; public class SpaceReplace 4 public static void main (String [1 ares) f( Scanner scnr-new Scanner(System.in); String firstName; String lastName; Your solution goes here */ 10 12

  • A person's initials consist of the first letter (in upper case) of each of their names....

    A person's initials consist of the first letter (in upper case) of each of their names. For example, the initials of Alan Mathison Turing are AMT. Use loops to print out all possible initials for people who have exactly three names. Cycle through the letters of the first initial first, followed by the middle initial, and then the last initial. Python Programming A person's initials consist of the first letter (in upper case) of each of their names. For example,...

  • In python: ScoreFinder is a function that takes in two lists and a string. The first...

    In python: ScoreFinder is a function that takes in two lists and a string. The first list is a list of strings (player names), the second list is a list of floats (player scores), and the string is a name (player to find). If the player to find exists in the list of player names, then print the name of that player along with their associated score (which is in the second list at the same index). If the player...

  • 1. Write a program to input a list of names (strings) from the user and store...

    1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or by entering the string “quit”. 2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For...

  • Problem 1 In this problem, you will write two functions. The first function takes in a...

    Problem 1 In this problem, you will write two functions. The first function takes in a string and returns that string without any dashes. The second function takes in the first and last name and returns a string that is lastname_firstname and uses the previous function to remove any dashes (-) in the name. Note that you’ll be testing it by calling it from the command line; you’ll call it from a script in problem 3. Deliverables: Function file that...

  • Write a function full_name(first_name, last_name) that takes a person's first name and last name as parameters...

    Write a function full_name(first_name, last_name) that takes a person's first name and last name as parameters and returns their full name made up of the first name, a space character and their last name all concatenated together. For example: Test Result name = full_name('Alex', 'Ng') print(name) Alex Ng print(full_name('Malcolm', 'X')) Malcolm X

  • In C Write a function that asks for the user's first, middle, and last names. The...

    In C Write a function that asks for the user's first, middle, and last names. The names will be entered by the user on a single line and will be stored in three different C-strings. The program should then store, in a fourth array, the name arranged in the following manner: the last name followed by a comma and a space, followed by the first name and a space, followed by the middle name. For example, if the user entered...

  • PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number)...

    PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number) and prints: My name is <name> and I am <age> years old(where name and age are the inputs) 2. Write a function that takes as input a and b and returns the result of: ??ab 3. Write a function that takes as input a and b and returns the result of: ??ab if it is valid to divide a and b 4. Write a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT