Command Palette

Search for a command to run...

Hectal
Phase 4: Lists, Tuples, Dictionaries and Sets
Python · Exercise 6 of 6 Previous
Beginner

Pick passing students and keep a backup

students is a list of dictionaries, each with a "name" and a "marks" number.

With a list comprehension, make passed: the names of students with marks of 50 or more, in the same order. With a dictionary comprehension, make by_name: each name mapped to that student's marks.

Make backup as a deep copy of students, using copy.deepcopy (the starter already has import copy at the top). Replace the line backup = students, which only gives the list a second name.

The last line of the starter, students[0]["grace"] = 5, adds a "grace" entry to the first student. Keep it after you make backup. backup must stay unchanged.

What Check tests

  1. passed is ["Asha", "Tom"]
  2. by_name maps names to marks
  3. The first student of students has the grace entry
  4. backup is not changed
  5. backup is a separate object with the same names
  6. backup shares no student dictionary with students

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.