Sublist
From Exercism PythonMITOriginal pagePython1 class period1 exercise22 graded tests
README.md
Sublist
Instructions
Given any two lists A and B, determine if:
- List
Ais equal to listB; or - List
Acontains listB(Ais a superlist ofB); or - List
Ais contained by listB(Ais a sublist ofB); or - None of the above is true, thus lists
AandBare unequal
Specifically, list A is equal to list B if both lists have the same values in the same order.
List A is a superlist of B if A contains a contiguous sub-sequence of values equal to B.
List A is a sublist of B if B contains a contiguous sub-sequence of values equal to A.
Examples:
- If
A = []andB = [](both lists are empty), thenAandBare equal - If
A = [1, 2, 3]andB = [], thenAis a superlist ofB - If
A = []andB = [1, 2, 3], thenAis a sublist ofB - If
A = [1, 2, 3]andB = [1, 2, 3, 4, 5], thenAis a sublist ofB - If
A = [3, 4, 5]andB = [1, 2, 3, 4, 5], thenAis a sublist ofB - If
A = [3, 4]andB = [1, 2, 3, 4, 5], thenAis a sublist ofB - If
A = [1, 2, 3]andB = [1, 2, 3], thenAandBare equal - If
A = [1, 2, 3, 4, 5]andB = [2, 3, 4], thenAis a superlist ofB - If
A = [1, 2, 4]andB = [1, 2, 3, 4, 5], thenAandBare unequal - If
A = [1, 2, 3]andB = [1, 3, 2], thenAandBare unequal
Open the
01folder and editmain.py. Run Tests checks it.
For teachers
Sublist
Students solve Exercism's “Sublist” Python exercise in CS Room, with Exercism's own tests.
- Time: 1 class period
- Tests: 22, set up for you when you import the lesson
- Practices: comparisons