Menu
CoddyTech

List Equality Changes

Lesson 8 of 48 in Coddy's Python for Dart Developers course.

Dart's ordinary List equality is identity-based unless another implementation provides a different operator. Python list equality compares elements by value. Dart identical checks object identity; Python is fills that role. Assignment aliases a list in both languages, while separate list literals produce separate mutable objects. Custom classes can override equality in each language, so reason from the actual type rather than operator spelling alone. Use Python equality for string content and identity for deliberate singleton checks. Constant canonicalization and implementation caching make incidental identity tests unsuitable for ordinary value comparisons.

Dart

void main() {
  final a = [4];
  final b = [4];
  print(a == b);
  print(identical(a, b));
}

Python

a = [4]
b = [4]
print(a == b)
print(a is b)

Porting trap

Two newly allocated lists with the same integers can compare unequal in Dart and equal in Python. Port the intended equality contract explicitly.

challenge icon

Challenge

Beginner

Read two text labels on separate lines. The reserved token missing means an absent label; all other lines, including an empty line, are actual strings. The scaffold converts that token to None. Print whether the labels have equal values, then whether the first is absent, then whether the second is absent, one Python boolean per line.

Print only these lines, ending each with a newline. Keep the supplied input scaffold; it reads the stated values without prompts.

Your code goes in main.py. The locked driver.py starts your program and cannot be edited.

Try it yourself

# Starts the program in main.py. Edit main.py to solve the challenge.
from runpy import run_module

run_module("main", run_name="__main__")
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Python for Dart Developers

Practice on your own: Online Python compiler