Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

After squandering precious minutes last year drawing and redrawing names out of a hat, this year you resolve to write a program to assign pairs

image text in transcribed

After squandering precious minutes last year drawing and redrawing names out of a hat, this year you resolve to write a program to assign pairs for the annual Christmas gift exchange. Your gift exchange program has five requirements: The pairings should be random Each gifter should be matched with one recipient Each recipient should be matched with one gifter No person may be paired with himself or herself Other unpermitted combinations need to be avoided Write a function assign_pairs that takes a list of names and a list of unpermitted pairings (as unordered pairs of names) and returns a dictionary of pairs according to the above requirements. The keys of the dictionary designate the gifters and the corresponding value designates the recipient. Here is an example of the function usage: # List of names names = ["Li", "Fatima", "Jaime", "Jamila", "Vincentius", "Nike", "Jean", "Sheila"] # Unpermitted pairs as a list of unordered pairs unpermitted_pairs = [{"Li", "Sheila"},{"Fatima", "Jaime"},{"Jamila", "Vincentius"}] pairs = assign_pairs(names, unpermitted_pairs) print(pairs) # One possible output {'li': 'Jean', 'Fatima': 'Jamila', 'Jaime': 'Sheila', 'Jamila': 'Nike', 'Vincentius': 'li', 'Nike': Your function should be defined as follows: def assign_pairs (names, unpermitted_pairs): # write some code here You may use the example above for debugging. The grading code tests that your function fulfills the above requirements and uses other lists than the example provided. Make sure to not hard-code your results. Note: Unlike an ordered pair (i.e. a tuple) which sees (a, b) and (b, a) as different, an unordered pair (i.e. a set) sees {a, b} and {b, a} as equivalent. Hint: The shuffle function shuffles a list in-place

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions