preferences_dictionary = {1: [4, 2, 1, 3],2: [4, 3, 1, 2],3: [4, 3, 1, 2],4: [1, 3, 4, 2],5: [2, 3, 4, 1],6: [2, 1, 3, 4]}
Above is the preferences_dictionary and i need to fetch the the first value which is at position 0 for all the keys i.e most preferred no. in case of the list shown above it should be 4, as keys 1,2,3 prefer 4 over rest in the values.
Code that i used, but it is not overwriting the value:
preferences_dictionary = {1: [4, 2, 1, 3],2: [4, 3, 1, 2],3: [4, 3, 1, 2],4: [1, 3, 4, 2],5: [2, 3, 4, 1],6: [2, 1, 3, 4]}
def plu (preferences): sortedlist=sorted(preferences,reverse=True)
firstElementDict={}
for agent, sortedlist in firstElementDict.items():
firstElementDict=sortedlist[0]
print(firstElementDict)