Created
August 16, 2017 18:22
-
-
Save rlingineni/5d3d984ff1e18d70c8a2e35106f8ba48 to your computer and use it in GitHub Desktop.
Dr.Chrono Rock_Collection Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Complete the function below. | |
def get_rock_index(quantity): | |
jamie = quantity | |
print jamie | |
ned = list(quantity) | |
ned.sort() | |
print ned | |
geoffrey = [] | |
i = 0 | |
for num in jamie: | |
sum = jamie[i] + ned[i] | |
geoffrey.append(sum) | |
i+=1 | |
print(geoffrey) | |
print HF(geoffrey)['index'] | |
return HF(geoffrey)['index'] | |
#highest frequency dictionary | |
def HF(list): | |
D = {} | |
i = 0 | |
for num in list: | |
if not num in D: | |
D[num] = {"index":i, "count":1} #each item keeps track of count and the last found index | |
else: | |
newCount = D[num]['count'] + 1 | |
D[num] = {"index":i, "count": newCount} | |
i+=1 | |
max = 0 | |
result = {} | |
for key,val in D.items(): | |
if key > max: #Get the MAX key | |
max = key | |
result = val | |
return result | |
original = [7,7,9,1,2,4] | |
get_rock_index(original) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment