-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsublist.py
More file actions
36 lines (30 loc) · 1.12 KB
/
sublist.py
File metadata and controls
36 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
This exercise stub and the test suite contain several enumerated constants.
Enumerated constants can be done with a NAME assigned to an arbitrary,
but unique value. An integer is traditionally used because it’s memory
efficient.
It is a common practice to export both constants and functions that work with
those constants (ex. the constants in the os, subprocess and re modules).
You can learn more here: https://en.wikipedia.org/wiki/Enumerated_type
"""
# Possible sublist categories.
# Change the values as you see fit.
# Possible sublist categories.
# Possible sublist categories.
SUBLIST = "sublist"
SUPERLIST = "superlist"
EQUAL = "equal"
UNEQUAL = "unequal"
def sublist(list_one, list_two):
if list_one == list_two:
return EQUAL
len_one, len_two = len(list_one), len(list_two)
if len_one <= len_two:
for i in range(len_two - len_one + 1):
if list_two[i:i + len_one] == list_one:
return SUBLIST
if len_one >= len_two:
for i in range(len_one - len_two + 1):
if list_one[i:i + len_two] == list_two:
return SUPERLIST
return UNEQUAL