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
BeginnerRead 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__")
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Python for Dart Developers
1From Dart to Python
Run Your First Python ProgramInterpolation and printvar, final, and Python NamesFloor Versus TruncationBraces and Block ScopeRecap: Rewrite a Receipt4Iteration and Transformations
for-in and rangeentries and enumerateLoop Updates and continuewhere, map, and List BuildingRecap: Build a Ranking2Values and Decisions
Null Safety and NoneList Equality ChangesConditions and Null DefaultsTernaries and elifRecap: Eligibility Rules3Collections and References
Lists and Negative IndexesRecords and Tuple UnpackingMap Lookups and KeyErrorSets and Shared ObjectsRecap: Clean an Inventory6Reliable Python Programs
stdin and Exact Formattingon, catch, finally, and withLibraries and Import ExecutionStatic Types Versus HintsRecap: Validate a Batch9Project: Order Processing
Create the Order ModelAdd Pricing PoliciesPractice on your own: Online Python compiler