sublist.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
EQUAL = 0
SUBLIST = 1
SUPERLIST = 2
UNEQUAL = 3


def list_in_list(little, big):
    # Find little list in big list
    n = len(little)
    sublists = (big[i:i+n] for i in range(0, len(big)))
    return little in sublists


def check_lists(list1, list2):
    if list1 == list2:
        return EQUAL

    if len(list1) > len(list2):
        return SUPERLIST if list_in_list(list2, list1) else UNEQUAL

    if len(list1) < len(list2):
        return SUBLIST if list_in_list(list1, list2) else UNEQUAL

    return UNEQUAL

Comments


You're not logged in right now. Please login via GitHub to comment