We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Dictionaries

Dictionaries in Python are used to store data values in key -> value pairs. Dictionaries are a great way to store groups of information.

# use curly braces
# add key-value pairs
car = {
  "brand": "Toyota",
  "model": "Camry",
  "year": 2019,
}

Here the car variable is assigned to a dictionary {} containing the keys brand, model and year. The keys' corresponding values are Toyota, Camry and 2019.

Assignment

Complete the get_character_record function. It takes a character's name, server, level, and rank as individual inputs, and returns a dictionary with the following string keys:

  • "name"
  • "server"
  • "level"
  • "rank"
  • "id"

Next, we can't have two characters named bloodwarrior123 on the same server!

Concatenate the name and the server inputs with a # in the middle. For example, given:

  • name = "bloodwarrior123"
  • server = "server1"

Then the id field would be set to bloodwarrior123#server1.

Tips

  • You can return the dictionary directly without assigning it to a variable.
  • I recommend using an f-string to create the id field. This is a best practice.