1

I have a homework, I have a dictionnary of grades and I need to take all the values to find the average of these grades. But I don't know how to take only the values {"DM1" : 90} I just need the 90. Can someone help please. Thanks

bulletin = {"DS1": 15, "DM1": 13, "DS3": 14, "DM2": 15, "TP": 18, "DM3": 16, "DS3": 11} 

into

grades = [] 
deadshot
  • 8,881
  • 4
  • 20
  • 39
pepitoo999
  • 33
  • 6

3 Answers3

3

grades = list(bulletin.values()) should do the job.

muhmann
  • 191
  • 9
2

Here is the code; It creates the dictionary with the keys and values, then it creates the list, assigning the list binding of the dictionary and then finding the values of those keys, finally it outputs the result.

# Create the dictionary
bulletin = {"DS1": 15, "DM1": 13, "DS3": 14, "DM2": 15, "TP": 18, "DM3": 16, "DS3": 11}

# Create a list and get the key values from the dictionary
grades = list(bulletin.values())

# Output the result
print(grades)

Works like a charm:

Working Code

James Barnett
  • 561
  • 5
  • 18
-1

The inbuilt method you are searching for is named .values() have a look on the python docs: Python - Built in Types