Question

Python pls create a function called search_position. This function returns a list of 2 tuples and...

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

Homework Answers

Answer #1
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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python pls create a function called search_position. This function returns a dictionary. team1 = {'Fiora': {'Top':...
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}}
python pls Create function math_life() this function takes one or more argument. If this function called...
python pls Create function math_life() this function takes one or more argument. If this function called with no argument, raise typeError. The math_life() function returns to a function defined inside. this will take a one argument. For the second argument, it will calculate second function passed to math_life(). You should assume that the math_life() passed x functions, when it called the x times it will calculate the xth function passed to math_life() arguments when it called x+1 time it again...
create a function that takes a dictionary and returns a list of int. The list should...
create a function that takes a dictionary and returns a list of int. The list should appear in decreasing order based on the sum of number in each dictionary. def total_num(dict1): #Code here input = {1: {'una': 5, 'dos': 7, 'tres': 9, 'quar' : 11}, 2: {'dos':2, 'quar':3}, 3:{'una': 3, 'tres': 5}, 4:{'cin': 6}, 5:{'tres': 7 , 'cin': 8}} output = [1,5,3,4,2] 1: 38 2: 5 3: 8 4: 6 5: 15 1>5>3>4>2
Function name : matrixMultiplication Parameters : aMatrix (list), bMatrix (list) Returns Type: list of tuples Description...
Function name : matrixMultiplication Parameters : aMatrix (list), bMatrix (list) Returns Type: list of tuples Description : Write a function in PYTHON that takes in two matrices (list of tuples or list of lists) and multiplies the two matrices together. Assume that the given matrices will be valid, i.e. aMatrix will be n x m (n rows and m columns) and bMatrix will be m x ℓ (m rows and ℓ columns). *Assume elements of aMatrix & bMatrix will be...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n,...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n, a positive integer, it returns a list of n tuples corresponding to the numbers 1 through n (both inclusive): the tuple for the number k consists of k as the first component, and exactly one of the following strings as the second: • the string 'two!' if k is divisible by 2 • the string 'three!' if k is divisible by 3 • the...
c) A function named tallied_data() that takes in a nested list (Use this on the data...
c) A function named tallied_data() that takes in a nested list (Use this on the data from part 1, but it should be able to be used to solve similar problems), indices for two columns and returns a tallied list. The inputs are: i) a nested list, ii) an index for the ‘reference column’/ ‘category’ (col_ref) iii) another index for the column to be tallied (col_tally) iv) this function returns a list of tuples where each element is a tuple...
Write a function called score that meets the specifications below. def score(word, f): """ word, a...
Write a function called score that meets the specifications below. def score(word, f): """ word, a string of length > 1 of alphabetical characters (upper and lowercase) f, a function that takes in two int arguments and returns an int Returns the score of word as defined by the method: 1) Score for each letter is its location in the alphabet (a=1 ... z=26) times its distance from start of word. Ex. the scores for the letters in 'adD' are...
In Python: Problem 5] Write a function that accepts a list as argument and returns a...
In Python: Problem 5] Write a function that accepts a list as argument and returns a list that contains: (1) The positive elements of the taken list (2) The negative elements of the taken list (3) The odd elements of the taken list (4) The even elements of the taken list
Write a function called matches that takes two int arrays and their respective sizes, and returns...
Write a function called matches that takes two int arrays and their respective sizes, and returns the number of consecutive values that match between the two arrays starting at index 0. Suppose the two arrays are {3, 2, 5, 6, 1, 3} and {3, 2, 5, 2, 6, 1, 3} then the function should return 3 since the consecutive matches are for values 3, 2, and 5. in C++ Im confused how to start this, any hints are great and...
python 3 For this exercise you are to implement the function poly_iter in the array-backed list...
python 3 For this exercise you are to implement the function poly_iter in the array-backed list class, which, when called with positive integer parameters a, b, c, returns an iterator over the values in the underlying list at indexes a*i2+b*i+c, for i=0, 1, 2, ... E.g., given an array-backed list lst containing the elements [0, 1, 2, 3, 4, ..., 98, 99], the following code: for x in lst.poly_iter(2, 3, 4): print(x) will produce the output: 4 9 18 31...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT