Python pls
create a function called search_position. This function returns a list of 2 tuples and the number should be start highest number. The first index is the number, and second are list of 2 tuples that sorted by position in alphabetical order: The first index will be position and second index will be champion's name(This also should be sorted by alphabetical order).
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):
#enter the code
and this function should 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'])])]
####The output should start with highest number + alphabetical order
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(team):
# creatin the empty array to store result
A = []
# looping through each champion
for t in team:
# looping through champions's data
for s in team[t]:
index = -1
for i in range(len(A)):
if A[i][0] == team[t][s]:
index = i
break
if index == -1:
A.append((team[t][s], [(s, [t])]))
else:
index2 = -1
for i in range(len(A[index][1])):
if A[index][1][i][0] == s:
index2 = i
break
if index2 == -1:
A[index][1].append((s, [t]))
else:
A[index][1][index2][1].append(t)
# sorting the chapion names of result in alphabetic order
for a in A:
for b in a[1]:
b[1].sort()
# sorting outer tuple in descending order of their number
A.sort(reverse = True, key = lambda x: x[0])
# returning the result array
return A
print(search_position(team1))
OUTPUT:-
if you have any doubt, feel free to ask in the comments.
Get Answers For Free
Most questions answered within 1 hours.