Question

In: Computer Science

Python pls create a function called search_position. This function returns a list. team1 = {'Fiora': {'Top':...

Python pls

create a function called search_position. This function returns a list.

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):

returns

[(5, [('Top', ['Yasuo'])]),

(4, [('Mid', ['Fiora']), ('Support',['Olaf']), ('Jungle',['Shaco'])])  

(3, [('Bottom', ['Fiora']), ('Top', ['Olaf'])]),

(2, [('Mid', ['Olaf','Yasuo']), ('Top', ['Shaco'])]),

(1, [('Mid', ['Shaco'])])]

Solutions

Expert Solution

Raw_code:

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}
}

# search_position function definition
def search_position(team1):
# result variable of list type for storing result
result = []
# checking whether the input team1 is dictionary type or not
if isinstance(team1, dict):
# iterating through each dict item in team1
for key, value in team1.items():
#checking whether each value in dict item is dictionary type or not
if isinstance(value, dict):
# iterating through each key, value in value dict
for skey, svalue in value.items():
# if result is empty, first element in team1 is added to the result
if len(result) == 0:
result.append((svalue, [(skey, [key])]))
else:
# iterating through each element in result
for element in result:
# if any main key in element in result equals to sub value in value
if element[0] == svalue:
# iterating through each subvalue in main key in element in result
for subelement in element[1]:
# if subkey in value of main key in reuslt is equals to sub key in value
if subelement[0] == skey:
# append subvalue in value to it
subelement[1].append(key)
break # breaking for loop
else:
# else, appending tuple of subkey and list of subvalue to value of main key in result
element[1].append((skey, [key]))
break
# if no main key with subvalue in team1 not found
# appending tuple of subvalue and list of tuple of subkey and list of key
else:
result.append((svalue, [(skey, [key])]))

# storing the result according to the mainkey in result
for i in range(len(result)):
for j in range(i+1, len(result)):
if result[i][0] < result[j][0]:
result[i], result[j] = result[j], result[i]

return result

# calling search_position with team1 as parameter
team = search_position(team1)
# iterating through each element in team and print the element
for i in team:
print(i)


Related Solutions

Python pls Create a function party_freq(dicto:dict): this function returns a list inside tuple that how many...
Python pls Create a function party_freq(dicto:dict): this function returns a list inside tuple that how many times each person party in the day. For example def party_freq(dicto:dict) -> [(str,{(int,int,int): int})]: #code here input dict1 ={'fire1': {(2000,5,20,480) : ('Aaron', 25, 300, ( 0, 300)), (2000,5,20,720) : ('Baily', 45, 1500, (1500,500)), (2000,5,21,490) : ('Aaron', 35, 500, (1300,500)) }, 'fire2': {(2000,5,20,810) : ('Baily', 45, 1400, (600,1600)), (2000,5,20,930) : ('Baily', 43, 1800, ( 0, 0)) }} output [('Aaron', {(2000,5,20): 1, (2000,5,21): 1}), ('Baily', {(2000,5,20):...
In Python Create a function called ℎ?????. The function has as arguments a list called ??????...
In Python Create a function called ℎ?????. The function has as arguments a list called ?????? and a list call center. • List ?????? contains lists that represent points. o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates). • List ??????...
Python pls Create a function dict_sum. This function takes a dictionary and sums up the values...
Python pls Create a function dict_sum. This function takes a dictionary and sums up the values in the dictionary. For example: dict1 = {1: {'una': 5, 'dos': 7, 'tres': 9, 'quar' : 11}, 2: {'dos':2, 'quar':4}, 3:{'una': 3, 'tres': 5}, 4:{'cin': 6}, 5:{'tres': 7 , 'cin': 8}} dict2 = {300:{'s': 300}, 400:{'s': 100, 'g': 100, 'p': 100}, 500: {'s': 50 ,'m': 400, 'p':30, 'i': 50}, 600: {'s': 40, 'i': 400}, 700: {'m': 100, 'p': 50}} def dict_sum(db): should give output...
PYTHON PLS 1) Create a function search_by_pos. This function only has one return statement. This function...
PYTHON PLS 1) Create a function search_by_pos. This function only has one return statement. This function returns a set statement that finds out the same position and same or higher skill number. This function searches the dictionary and returns the same position and same or higher skill level. The function output the set statements that include the position only. For example input : dict = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2,...
In Python Create a function called ????. The function receives a "string" that represents a year...
In Python Create a function called ????. The function receives a "string" that represents a year (the variable with this "String" will be called uve) and a list containing "strings" representing bank accounts (call this list ????). • Each account is represented by 8 characters. The format of each account number is "** - ** - **", where the asterisks are replaced by numeric characters. o For example, “59-04-23”. • The two central characters of the "string" of each account...
python pls create a function party_place: that search the dictionary and figure out where they party...
python pls create a function party_place: that search the dictionary and figure out where they party in that day. For example def party_place(dict2: dict, date: (int,int,int)): dict1= {'fire1': {(2000,5,20,480) : ('Aaron', 25, 300, ( 0, 300)), (2000,5,20,720) : ('Baily', 45, 1500, (1500,500)), (2000,5,21,490) : ('Aaron', 35, 500, (1300,500)) }, 'fire2': {(2000,5,20,810) : ('Baily', 45, 1400, (600,1600)), (2000,5,20,930) : ('Baily', 43, 1800, ( 0, 0)) }} output print(party_place(dict1, (2000,5,20,720)) = ['fire1', 'fire2'] print(party_place(dict1, (2000,5,21,720)) = ['fire1'] print(party_place(dict1, (2000,5,22,720)) = []
IN PYTHON Create a function called biochild.  The function has as parameters the number m...
IN PYTHON Create a function called biochild.  The function has as parameters the number m and the lists biomother and biofather.  The biomother and biofather lists contain 0’s and 1’s.  For example: biomother = [1,0,0,1,0,1] and biofather = [1,1,1,0,0,1]  Both lists have the same length n.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child).  The child...
Please use Python to create a method for a linked list that returns the index of...
Please use Python to create a method for a linked list that returns the index of a lookup value within the linked lust
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
Write a Python function that returns a list of keys in aDict with the value target....
Write a Python function that returns a list of keys in aDict with the value target. The list of keys you return should be sorted in increasing order. The keys and values in aDict are both integers. (If aDict does not contain the value target, you should return an empty list.) This function takes in a dictionary and an integer and returns a list. def keysWithValue(aDict, target): ''' aDict: a dictionary target: an integer ''' # Your code here
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT