Files
python/exercises/sublist/example.py

31 lines
572 B
Python
Raw Normal View History

2014-04-09 07:34:19 -03:00
SUBLIST = 0
SUPERLIST = 1
EQUAL = 2
UNEQUAL = 3
def check_lists(l1, l2):
if l1 == l2:
return EQUAL
if contains(l1, l2):
2014-04-09 07:34:19 -03:00
return SUPERLIST
if contains(l2, l1):
2014-04-09 07:34:19 -03:00
return SUBLIST
return UNEQUAL
def contains(l1, l2):
if not l2:
return True
if len(l2) > len(l1):
2014-04-09 07:34:19 -03:00
return False
for i in range(len(l1) - len(l2) + 1):
if l1[i] != l2[0]:
continue
for j in range(len(l2)):
if l1[i + j] != l2[j]:
break
else:
2014-04-09 07:34:19 -03:00
return True
return False