Coding exercise on YAML

Representing complex data using YAML data serialization format.

We'll cover the following

Problem

See the example YAML data below. It demonstrates the usage of a list of dictionaries and a dictionary within a dictionary.

---
employee: 
  id: 1
  name: smith
  salary: 10000
  address: 
    city: toronto
    state: ontario
    country: canada 
    zip: A2NY1J
  commission: 
    - 
      quarter: Q1 2020
      amount: 1000
    - 
      quarter: Q2 2020
      amount: 1000

Now add another employee to the above document with data from the table below:

id name salary address commission
2 james 10000 city: seattle $500 for Q1 2020
state: washington $700 for Q2 2020
country: united states
zip: 32001

Try it yourself

Before looking at the solution, please try solving it yourself in the code editor provided below.

Note: As YAML is not a programming language, the Run button below the code editor will only print the YAML code. You may ignore the Run button and simply compare manually your solution with my solution provided below.

Get hands-on with 1400+ tech skills courses.