Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overwatch is a multiplayer game so we strive to find the best match between each player. In this problem, you are given a dictionary containing

Overwatch is a multiplayer game so we strive to find the best match between each player. In this problem, you are given a dictionary containing each player's name and their score record list. For each player, you have to follow the following rules to find the matched players:

  • The difference between both player's max score should not exceed 5 points
  • The difference between both player'smin score should not exceed 5 points

Note: Theabs() function may be useful for judging this requirement

There may be more than one matched player for each player, and it is also possible that some players have no matched opponent (that may be because they are the best!)

Example:score_match({'Sombra': [10,22,24], 'Tracer': [13,25,24], 'Bastion':[23,38,10], 'Widowmaker':[14,39,40]})

We will first evaluate Sombra. Their min is 10 and max is 24. We want to compare these values to the other players' min and max values.

  • Tracer has a min of 13 and max of 25. The difference between the mins is 3, so it meets the requirement as it does not exceed 5. The difference between the maxes is 1, so it also meets the requirement.
  • Bastion has a min of 10 and max of 38. The difference between the mins is 3, which is valid, but the difference between the maxes is 13, so we cannot match Bastion with Sombra.
  • Widowmaker has a min of 14 and a max of 39. The difference between the mins is 4, which is valid, but the difference between the maxes is 15, so we cannot match Widowmaker with Sombra.
  • Thus, Tracer is the only valid match for Sombra.

Next, we will evaluate Tracer. We will follow the same process of evaluating every other player in the dictionary and only keep the players that meet the requirements of min and max difference thresholds. This process will continue for every player in the dictionary.

Our output will look like:

{'Sombra': ['Tracer'], 'Tracer': ['Sombra'], 'Bastion': ['Widowmaker'], 'Widowmaker': ['Bastion']}

Note: Make sure you sort the list of matched players inAlphabetical Ascending Order. (The functionsorted() might be useful here)

Return the dictionary with the player's name as the keys and the lists of matched players as the values.

Note: Make sure that the output value lists don't contain the playersthemselves.You should also make sure that the input dictionary has non-empty score lists.

Requirements: assert statements, list comprehension

Extra Credit (5 points): Construct the returned dictionary with adictionary comprehension (will be explained in the discussion), which is a dictionary version of list comprehension. The format is:

{key : value for ... in ...}.

Note: If you choose not to do the extra credit,you are allowed to use a loop in order to loop through the given dictionary. However, you must still use list comprehension to process each value list in the dictionary.

defscore_match(players):

"""

>>> score_match({'Sombra': [10,22,24],'Tracer': [13,25,24],

... 'Bastion':[23,38,10],'Widowmaker':[14,39,40]})

{'Sombra': ['Tracer'], 'Tracer': ['Sombra'], 'Bastion': ['Widowmaker'], \

'Widowmaker': ['Bastion']}

>>> score_match({'Sombra': [19,22,22],'Tracer': [20,24,24],

... 'Bastion':[22,23,25]})

{'Sombra': ['Bastion', 'Tracer'], 'Tracer': ['Bastion', 'Sombra'], \

'Bastion': ['Sombra', 'Tracer']}

>>> score_match({'Hanzo': [21],'Mei': [20,24,24], 'Bastion':[10]})

{'Hanzo': ['Mei'], 'Mei': ['Hanzo'], 'Bastion': []}

"""

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions