Given an array (or list) of scores, return the array of _ranks_ for each value in the array.  The largest value has rank 1, the second largest value has rank 2, and so on. Ties should be handled by assigning the same rank to all tied values. For example:

    ranks([9,3,6,10]) = [2,4,3,1]

and

    ranks([3,3,3,3,3,5,1]) = [2,2,2,2,2,1,7]
    
because there is one 1st place value, a five-way tie for 2nd place, and one in 7th place.

Difficulty: introductory

Starter code:

def ranks(a):
	

Solutions:
def ranks(a):
  sortA = sorted(a, reverse=True)
  return [sortA.index(s) + 1 for s in a]


def ranks(results):
    ranks = {}
    for k, v in enumerate(sorted(results, reverse=True), start=1):
        if not v in ranks:
            ranks[v] = k
    return [ranks[i] for i in results]

def ranks(a):
    return [sorted(a, reverse = True).index(m) + 1 for m in a]

def ranks(a):
    dict = {v: k for k, v in sorted(enumerate(sorted(a, reverse=True), start=1), reverse=True)}
    return [dict[i] for i in a]


import copy

def ranks(lst):
    sortedVals = copy.deepcopy(lst)     #need deep copy to not mutate original list
    sortedVals.sort(reverse=True)       #descending order
    
    rankVec = []
    for v in lst:                       #for every value in the list, calculate its rank
        indLoc = sortedVals.index(v)    #always finds first occurance so repetition does not matter
        rankOfVal = indLoc+1            #min rank is 1 not 0
        rankVec.append( rankOfVal )

    return rankVec
#---end function


from collections import Counter

def ranks(a):
    id, res = 1, {}
    for k,v in sorted(Counter(a).items(), reverse=True):
        id, res[k] = id+v, id
    return list(map(res.get, a))

def ranks(a):
    b = sorted(a, reverse=True)
    d = {i:b.index(i)+1 for i in a}
    return [d[i] for i in a]

def ranks(a):
    ranks = {}
    for rank, x in enumerate(sorted(a, reverse=True), 1):
        if x not in ranks:
            ranks[x] = rank
    return [ranks[x] for x in a]

def ranks(a):
    s = sorted(a)[::-1]
    return [(s.index(n) + 1) for n in a]


def ranks(a):
    rankarr = [None] + sorted(a)[::-1]
    return [rankarr.index(x) for x in a]