Skip to content

Instantly share code, notes, and snippets.

@rlingineni
Created August 16, 2017 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlingineni/5d3d984ff1e18d70c8a2e35106f8ba48 to your computer and use it in GitHub Desktop.
Save rlingineni/5d3d984ff1e18d70c8a2e35106f8ba48 to your computer and use it in GitHub Desktop.
Dr.Chrono Rock_Collection Python
# 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