The parameter represents a "person to friends" dictionary. This function must return a "last name to first names" dictionary...
View the step-by-step solution to:

Question

your boy is struggling out here


-------------------------------------------

def

get_last_to_first(

    person_to_friends: Dict[str, List[str]]) -> Dict[str, List[str]]:

  """Return a "last name to first name(s)" dictionary with the people from the

  "person to friends" dictionary person_to_friends.


  >>> get_last_to_first(P2F) == {

  ...  'Katsopolis': ['Jesse'],

  ...  'Tanner': ['Danny R', 'Michelle', 'Stephanie J'],

  ...  'Gladstone': ['Joey'],

  ...  'Donaldson-Katsopolis': ['Rebecca'],

  ...  'Gibbler': ['Kimmy'],

  ...  'Tanner-Fuller': ['DJ']}

  True

  """

  pass # Remove me when you've implemented this function



def invert_and_sort(key_to_value: Dict[object, object]) -> Dict[object, list]:

  """Return key_to_value inverted so that each key is a value (for

  non-list values) or an item from an iterable value, and each value

  is a list of the corresponding keys from key_to_value. The value

  lists in the returned dict are sorted.


  >>> invert_and_sort(P2C) == {

  ... 'Comet Club': ['Michelle Tanner'],

  ... 'Parent Council': ['Danny R Tanner', 'Jesse Katsopolis',

  ...           'Joey Gladstone'],

  ... 'Rock N Rollers': ['Jesse Katsopolis', 'Kimmy Gibbler'],

  ... 'Comics R Us': ['Joey Gladstone'],

  ... 'Stamp Club': ['Kimmy Gibbler']}

  True

  """

  pass # Remove me when you've implemented this function


invert_and_sort.pngget_last_to_first.pngbeeg yoshi.png

beeg yoshi.png

The parameter represents a "person to friends" dictionary. This function must return a "last name to first names" dictionary
built from the data in the given dictionary. The keys in the returned dictionary should be the last names of people in the given
dictionary. (Remember: every person has exactly one last name.) The values are lists of the first names (sorted in alphabetical
order) of people with a given last name.
get_last_to_first:
(Dict[str, List [str]]) -> Dict[str, List[str] ]
The returned dictionary should contain every person whose name appears in the given dictionary: the person's last name as
one of the dictionary keys, and the person's first name as an element in one of the dictionary values. Names in the list should
be unique: no one should be listed more than once. Use the list method sort to put the lists of first names into alphabetical
order.
The parameter represents a dictionary, in which either the values are all lists or none of the values are lists. This function must
return a new dictionary that is the given dictionary inverted: each key is a value or an item from a values list from the given
dictionary, and each value is a list of the corresponding keys from the given dictionary. The items in the new dictionary's
values lists are sorted.
For example, given the following argument (based on profiles. txt) :
{ 'Claire Dunphy' : ['Parent Teacher Association' ],
"Manny Delgado': ['Chess Club' ],
"Mitchell Pritchett': [' Law Association' ],
"Alex Dunphy' : ['Chess Club', 'Orchestra' ],
invert_and_sort:
Cameron Tucker' : ['Clown School' , 'Wizard of Oz Fan Club' ],
(Dict [object, object]) -> Dict[object, list]
Phil Dunphy': ['Real Estate Association' ],
'Gloria Pritchett': ['Parent Teacher Association' ]}
the function should return:
{ 'Parent Teacher Association': ['Claire Dunphy', 'Gloria Pritchett' ],
'Chess Club' : ['Alex Dunphy', 'Manny Delgado' ],
'Law Association': [ 'Mitchell Pritchett' ],
'Orchestra' : ['Alex Dunphy' ],
Clown School' : ['Cameron Tucker' ],
'Wizard of Oz Fan Club': ['Cameron Tucker' ],
'Real Estate Association' : ['Phil Dunphy' ]}

get_last_to_first.png

def get last to first(
person to friends: Dict [str, List [str]]) -> Dict[str, List [str]] :
""Return a "last name to first name (s)" dictionary with the people from the
"person to friends" dictionary person to friends.
>)> get last to first (P2F) == {
'Katsopolis' : ['Jesse'],
'Tanner' : [ 'Danny R', 'Michelle', 'Stephanie J' ] ,
'Gladstone' : [ ' Joey'] ,
'Donaldson-Katsopolis' : ['Rebecca' ] ,
'Gibbler' : ['Kimmy'] ,
"Tanner-Fuller': ['DJ' ])
True
pass
# Remove me when you've implemented this function

invert_and_sort.png

def invert and sort (key to value: Dict[object, object]) -> Dict[object, list] :
""Return key to value inverted so that each key is a value (for
non-list values) or an item from an iterable value, and each value
is a list of the corresponding keys from key to value. The value
lists in the returned dict are sorted.
>>> invert and sort (P2C) == {
"Comet Club': ['Michelle Tanner' ] ,
'Parent Council': ['Danny R Tanner', 'Jesse Katsopolis',
"Joey Gladstone'],
'Rock N Rollers': ['Jesse Katsopolis', 'Kimmy Gibbler'],
'Comics R Us': ['Joey Gladstone'],
'Stamp Club' : ['Kimmy Gibbler' ]}
True
pass
# Remove me when you've implemented this function

Top Answer

Please find the code and output below. Let me know if you have any doubt. from typing import List,Dict def invert_and_sort... View the full answer

2.PNG

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question