Choosing Between a Map and an Object

With Dev Patel on plot 3 and Ola Bakare added, Rosa’s waiting list now runs Hannah Cole, Marek Nowak, June Harris, and Ola Bakare. The booking page has to save that list between visits, and it stores everything as JSON text.

Rosa’s Python script keeps both the waiting list and each plot record in a dict, but your port uses a Map for one and an object for the other. Here you’ll learn to make that choice yourself, then get the Map into JSON and back.

Pick the Tool by Its Keys

In Python, one dict type does two jobs, a plot record and the waiting list:

Language: Python
plot = {"plot": 4, "section": "B", "holder": "Dara Quinn"}
waiting = {187: "Hannah Cole", 305: "Marek Nowak",
           42: "June Harris", 318: "Ola Bakare"}
print(plot["holder"], waiting[42])

It prints Dara Quinn June Harris. Look at where the keys come from. You typed "holder" because every plot record has that field, but the member numbers are data from the garden society’s list, and they’ll change next season.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.