Implementation of dictionary in Python

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error Implementation of dictionary in Python on this date .

I’m relatively new to Python (but not with programming) and I’m getting quite confused with how dictionaries work in Python. I have a program that saves the score of a current player. Whenever the game ends, I need to save the score in a dictionary with keywords ‘username’, ‘runtime’, and ‘errors’. So my final output would be something like:

Score – Username – RunTime – Error

10——-Jane——–7s——–3–

15——-Brian——-7s——–3–

12——-Dave——–7s——–3–

09——-Aura——–7s——–3–

In the terminal, I should display the output of the dictionary which I think should be:

{ '10' : ['username': Jane, 'runtime': 7s, 'errors':3], '15' : ['username': Brian, 'runtime': 7s, 'errors':3], and so on and so forth

Is this possible? What should be the workaround here? Thank you for the help

Answer

Each dictionary element consists of 2 parts: – key – value Keys should be unique and immutable (string, integers, sets etc..) The score is immutable (integer) but probably not unique. In case several players get the same amounts of scores, you will not be able to store their data under the same key.

Consider the following structures:

  1. DICTIONARY WITH USERNAME AS A KEY {Username: [Score, RunTime, Error], …}

  2. LIST OF LISTS [[Username, Score, RunTime, Error], …]