Loading video player…

Welcome to the Shipping Label Maker

In JavaScript, the plain object does the everyday work of Python’s dict, all the way to JSON, and a Set does the work of a set. Your project is to port the label script for Marta’s notebook shop.

Here’s a first taste, with order 1042’s insured value. Iris chose no cover, so the value is 0. This Python code reads it with .get() and a default of 50, which is only for orders without the key:

Language: Python
order = {"id": 1042, "insured_value": 0}
insured = order.get("insured_value", 50)
print(f"Insured value: £{insured}")

Python keeps the 0:

Language: Program Output
Insured value: £0

JavaScript objects have no .get(), so the port a Pythonista reaches for uses || instead:

Language: JavaScript
const order = { id: 1042, insured_value: 0 };
const insured = order.insured_value || 50;
console.log(`Insured value: £${insured}`);

It runs with no error and prints this:

Language: Program Output
Insured value: £50

With || in place of .get()’s default, Iris’s 0 came out as 50: cover she turned down. Ports like this can run without an error and give a different answer, and this course shows you where, and what JavaScript does instead.

Marta sells hand-bound notebooks and packs every order herself. Her Python script, shipping_label.py, picks the address, looks up the postage, tidies the tags, and prints the label as JSON. You’ll port it to JavaScript.

By the end of this course, you’ll be able to:

  • Write an order as an object literal, read it with a dot or brackets, and list its keys and entries
  • Fill in defaults with ?? and reach into nested data that may be missing with ?.
  • Drop repeated tags with a Set, and spot remote postcodes with string keys
  • Read pasted JSON with JSON.parse() and print the label with JSON.stringify()
  • Put Marta’s whole label script together in JavaScript

You only need to know Python’s dicts, sets, and json module as you use them every day: get(), keys(), items(), in, json.loads(), and json.dumps(). In JavaScript, you only need to know how to write a small program with const, if, template literals, and arrays.

A current version of Node and of Python is fine: the examples use Node 26 and Python 3.15.

The course mixes short videos and text lessons, with exercises where you write the code yourself. Every video has notes below it. A project puts the whole label script together, and a quiz and a summary close the course.

Next up: Reading an Order as an Object, where order 1042 goes from a Python dict to a JavaScript object literal.

Download

Sample Code (.zip)

11.5 KB
Download

Course Slides (.pdf)

882.8 KB

00:00 Welcome to From Dicts to JavaScript Objects for Pythonistas! In JavaScript, the plain object does the everyday work of Python’s dict, all the way to JSON.

00:11 Your project: port the label script for Marta’s notebook shop. Its shipping label shows each order’s insured value. The courier insures every parcel for fifty pounds, unless a customer like Iris turns the cover down.

00:26 Here’s a first taste.

00:29 Iris chose no cover, so order 1042’s insured value is zero. Python’s get gives orders without the key a default of fifty, and keeps her zero.

00:42 The JavaScript port a Pythonista reaches for runs with no error and prints fifty. Objects have no get, so the port uses ||: Iris’s zero came out as fifty, cover she turned down.

00:58 Ports like this can run without an error and give a different answer. This course shows you where, and what JavaScript does instead.

01:08 Marta sells hand-bound notebooks. Her Python script picks the address, looks up the postage, tidies the tags, and prints the label as JSON. You’ll port it to JavaScript.

01:23 By the end, you’ll turn dicts into objects, fill in defaults, use Sets, and read and write JSON. Then the project puts the label script together.

01:36 You only need to know Python’s dicts, sets and json as you use them every day, and enough JavaScript for a small program.

01:46 Short videos mix with text lessons and exercises, and every video has notes below it. A project, then a quiz and a summary, close the course. Next up is Reading an Order as an Object, a text lesson that starts from order 1042 as a Python dict.

Become a Member to join the conversation.