Python pls
create a function called search_position. This function returns a dictionary.
team1 = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2, 'Top': 5},'Shaco': {'Jungle': 4, 'Top': 2, 'Mid': 1}}
def search_position(team1):
should return
{'Top': {'Fiora': 1, 'Yasuo':5,'Olaf':3,'Shaco':},
'Jungle': {'Shaco': 4},
'Mid': {'Yasuo', 2, 'Fiora': 4,'Olaf':2},
'Bottom': {'Fiora': 3},
'Support': {'Olaf': 4}}
def search_position(team1): result = {} for player, positions in team1.items(): for position, value in positions.items(): if position not in result: result[position] = {} result[position][player] = value return result
# Testing the function here. ignore/remove the code below if not required team1 = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3}, 'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4}, 'Yasuo': {'Mid': 2, 'Top': 5}, 'Shaco': {'Jungle': 4, 'Top': 2, 'Mid': 1}} print(search_position(team1))
Get Answers For Free
Most questions answered within 1 hours.