List Equality vs Identity

Easy ⏱ 8 min 76% acceptance ★★★★☆ 4.4
Write compare_lists(a, b) that returns a tuple (equal, same_object) where equal is whether a == b (same contents) and same_object is whether a is b (same object in memory).

Examples

Example 1
Input
a = [1, 2, 3], b = [1, 2, 3]
Output
(True, False)
Explanation

Same contents but different list objects.

Example 2
Input
a = [1, 2], b = a
Output
(True, True)
Explanation

b is another name for the exact same object.

Constraints

  • Inputs are lists.

Topics

ListsIdentity

Companies

OracleDeutsche Bank

Hints

Hint 1

== compares values; is compares object identity.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.