How can I access values from a key that stores more than one value in a dictionary in python?

Minions

My dictionary looks like this:

{James: [10, 7, 9], 'Bob': [3, 8, 4], 'Charles': [6, 2, 5]}

What I want to do is, output each user's score in order of who got the highest score. And with their name. At the moment, I am only able to print the student with the highest score:

inverse = [(value, key) for key, value in score_dict.items()]

print (max(inverse)[1])

The output is:

James

The output that I am trying to get is:

James 10

Bob 8

Charles 6
Hossain Muctadir

You can simply create a list of tuples with userwise highscore and later sort it with score. Something like this,

x = {'James': [10, 7, 9], 'Bob': [3, 8, 4], 'Charles': [6, 2, 5]}
y = [(k, max(v)) for k, v in x.items()]
for k, v in sorted(y, key=lambda a: a[1], reverse=True):
    print (k, v)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I sort dictionary values by one key?

Can I SELECT more than one value from the same column

how can I create nested dictionary keys and assign them values from a list of namespaced key value pairs?

How I can find a key ordered in ascending order in treemap, if there are more than one max values?

How can I return from a method more than one variable?

How to print the Key for particular value in python dictionary if more values are present for one key?

Delete all the keys from the dictionary if the value matches for more than one key

How can I reference values from one dictionary to another dictionary or value in a plist?

how can I retrieve individual values from a multi value key in Swift 4/json dictionary?

How to access single key from multiple values of a dictionary in Python

How can I enter more than five values on one line?

How can I get more than one document from mongoDB?

how can i Copy Into from more than one Table ?? Snowflake

How to make a dictionary, in which multiple values access one value(Python)

How can I have more than one value for my php

How to access key, value in a python dictionary? (error: "need more than 1 value to unpack")

How can I remove more than one item from a listbox?

How to use find_in_set() function in Codeigniter to find more than one values from the database field which was stores as comma seperated values

How can I add values to just one key in a dictionary in python?

Python: merge a value of key if it exists more than one times within a same dictionary

How can I get input value more than one from console nodejs

In Oracle SQL how can i find all values in one column for which in another column exist more than one distinct value

Find and print key which having more than one value in python dictionary

How can I pull one item, from a list of dictionary items, using a single key:value pair?

How can I rename values in a dictionary with a corresponding key value?

Adding more than one value to a Key in a Dictionary with Tuple Values

JSON from an API request stores as a single key:value how do I convert it to a dictionary?

How can I get more than one value from the Redux store in a single statement?

Can I add more than one value for the?