import random
import itertools
import time
ELEM = 10
l = [[1, 3, 6, 10, 11, 14, 15, 16, 18, 19, 21, 23, 27, 29, 31, 34, 37, 38, 39, 44, 45, 49], [0, 3, 5, 7, 8, 9, 10, 12, 15, 16, 17, 18, 24, 26, 28, 30, 31, 34, 35, 36, 37, 38, 40, 44, 47, 49], [4, 5, 10, 11, 12, 13, 15, 19, 22, 23, 25, 26, 29, 31, 34, 35, 36, 38, 39, 41, 46, 48, 49], [0, 1, 4, 6, 7, 8, 10, 12, 13, 17, 20, 21, 22, 26, 30, 31, 36, 37, 38, 39, 40, 41, 43, 47, 49], [2, 3, 6, 8, 11, 15, 18, 22, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 38, 39, 41, 42, 45, 47, 49], [1, 2, 6, 9, 10, 11, 12, 14, 16, 18, 20, 21, 22, 26, 28, 29, 30, 31, 32, 34, 37, 38, 39, 40, 42, 43, 44, 45, 46, 48, 49], [0, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 20, 21, 22, 23, 25, 26, 29, 31, 33, 34, 35, 36, 37, 38, 42, 43, 45, 48], [1, 3, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 21, 22, 23, 24, 27, 29, 32, 33, 35, 36, 37, 46, 48], [1, 3, 4, 6, 7, 9, 10, 11, 14, 15, 16, 18, 21, 24, 25, 26, 28, 30, 31, 32, 33, 34, 39, 41, 43, 46, 47, 48, 49], [1, 5, 6, 7, 8, 10, 12, 14, 15, 16, 17, 18, 20, 22, 24, 25, 27, 30, 31, 33, 38, 40, 41, 44, 48, 49], [0, 1, 2, 3, 5, 6, 7, 8, 9, 11, 12, 14, 15, 16, 18, 19, 20, 22, 23, 26, 30, 31, 32, 34, 35, 37, 38, 39, 41, 44, 45, 46, 48], [0, 2, 4, 5, 6, 7, 8, 10, 12, 14, 15, 16, 17, 19, 21, 23, 24, 25, 31, 32, 34, 38, 43, 44, 45, 46, 47, 48, 49], [1, 2, 3, 5, 6, 7, 9, 10, 11, 14, 15, 17, 19, 20, 21, 22, 23, 27, 32, 33, 35, 39, 41, 43, 44, 45, 49], [2, 3, 6, 7, 14, 15, 17, 18, 19, 21, 24, 25, 29, 30, 31, 33, 36, 39, 40, 41, 42, 43, 46, 49], [0, 5, 7, 8, 9, 10, 11, 12, 13, 17, 19, 21, 23, 24, 26, 28, 36, 41, 44, 45, 46, 47, 49], [0, 1, 2, 4, 7, 8, 9, 10, 11, 12, 13, 16, 17, 20, 22, 27, 28, 32, 33, 34, 35, 36, 41, 43, 46, 47, 48], [0, 1, 5, 7, 8, 9, 10, 11, 15, 21, 23, 28, 29, 30, 31, 32, 35, 38, 39, 40, 41, 42, 43, 49], [1, 3, 7, 9, 11, 12, 13, 14, 15, 18, 19, 22, 23, 24, 27, 30, 31, 32, 33, 37, 43], [0, 1, 4, 5, 8, 9, 10, 13, 17, 19, 23, 24, 25, 33, 34, 35, 38, 41, 42, 44, 45, 46, 47, 49], [0, 2, 7, 10, 11, 12, 13, 14, 17, 18, 21, 23, 25, 29, 30, 31, 32, 33, 35, 40, 41, 44, 46, 48, 49], [3, 5, 6, 9, 10, 12, 15, 21, 22, 24, 25, 27, 31, 33, 34, 35, 38, 40, 43, 47, 48], [0, 3, 5, 6, 7, 8, 11, 12, 13, 14, 16, 19, 20, 22, 24, 25, 27, 28, 29, 30, 31, 36, 39, 42, 43, 44, 47], [2, 3, 4, 5, 6, 7, 9, 10, 12, 15, 17, 20, 21, 24, 25, 26, 28, 31, 32, 36, 37, 38, 39, 40, 41, 42, 44, 46, 47, 48], [0, 2, 6, 7, 10, 11, 12, 14, 16, 17, 18, 19, 25, 28, 30, 33, 35, 36, 39, 40, 41, 42, 43], [1, 4, 7, 8, 9, 11, 13, 14, 17, 18, 20, 21, 22, 25, 26, 32, 33, 34, 39, 40, 41, 42, 45, 46, 47, 48, 49], [2, 4, 6, 8, 9, 11, 13, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 32, 35, 36, 37, 44, 46, 47], [1, 2, 3, 4, 5, 6, 8, 10, 14, 22, 24, 25, 27, 28, 29, 34, 35, 38, 39, 41, 44, 48], [0, 4, 7, 9, 12, 15, 17, 20, 21, 25, 26, 29, 30, 32, 34, 35, 36, 37, 38, 41, 43, 44, 45, 48], [1, 5, 8, 14, 15, 16, 21, 22, 23, 25, 26, 30, 33, 34, 36, 38, 43, 44, 48], [0, 2, 4, 5, 6, 7, 13, 16, 19, 21, 25, 26, 27, 30, 33, 40, 43, 44, 49], [1, 3, 4, 5, 8, 9, 10, 13, 16, 17, 19, 21, 23, 27, 28, 29, 36, 38, 39, 40, 44, 46], [0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 13, 16, 17, 19, 20, 21, 22, 32, 36, 37, 42, 46, 49], [4, 5, 7, 8, 10, 11, 12, 15, 16, 17, 19, 22, 24, 25, 27, 31, 33, 38, 39, 41, 42, 43, 45, 46, 47, 49], [4, 6, 7, 8, 9, 12, 13, 15, 17, 18, 19, 20, 23, 24, 28, 29, 32, 35, 39, 47, 48, 49], [0, 1, 2, 4, 5, 6, 8, 10, 11, 15, 18, 20, 24, 26, 27, 28, 36, 37, 38, 39, 44, 48], [1, 2, 4, 6, 7, 10, 12, 15, 16, 18, 19, 20, 23, 25, 26, 27, 33, 36, 38, 45, 46, 47, 49], [1, 2, 3, 6, 7, 13, 14, 15, 21, 22, 23, 25, 27, 28, 30, 31, 34, 35, 44, 45, 47, 48], [0, 1, 3, 5, 6, 7, 10, 17, 22, 25, 27, 31, 34, 39, 40, 41, 45, 47], [0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 16, 18, 20, 22, 26, 27, 28, 30, 32, 34, 35, 41, 44, 45], [0, 2, 3, 4, 5, 8, 10, 12, 13, 16, 21, 22, 23, 24, 26, 30, 32, 33, 34, 37, 44, 46, 47, 48], [1, 3, 5, 9, 13, 16, 19, 20, 22, 23, 24, 29, 30, 37, 44, 45, 48, 49], [2, 3, 4, 8, 9, 10, 12, 13, 14, 15, 16, 18, 19, 22, 23, 24, 26, 27, 32, 37, 38, 43, 45, 46, 48, 49], [4, 5, 6, 13, 16, 18, 21, 22, 23, 24, 31, 32, 45, 48, 49], [3, 5, 6, 8, 11, 12, 13, 15, 16, 17, 20, 21, 23, 27, 28, 29, 32, 41, 44, 47, 48, 49], [0, 1, 5, 9, 10, 11, 12, 14, 18, 19, 21, 22, 25, 26, 27, 28, 29, 30, 34, 36, 38, 39, 40, 43, 46, 48, 49], [0, 4, 5, 6, 10, 11, 12, 14, 18, 24, 27, 32, 35, 36, 37, 38, 40, 41, 42, 46, 48], [2, 5, 7, 8, 10, 11, 13, 14, 15, 18, 19, 22, 24, 25, 30, 31, 32, 35, 39, 41, 44, 45, 47], [1, 3, 4, 8, 11, 14, 15, 18, 20, 21, 22, 24, 25, 32, 33, 35, 36, 37, 39, 43, 46, 49], [2, 5, 6, 7, 8, 9, 10, 11, 15, 19, 20, 22, 24, 26, 27, 28, 33, 34, 36, 39, 40, 41, 42, 43, 44, 45], [0, 1, 2, 3, 4, 5, 8, 9, 11, 12, 13, 14, 16, 18, 19, 24, 29, 31, 32, 33, 35, 40, 41, 42, 43, 44, 47]]
def ajout_sublist(l):
longueur = random.randint(0, ELEM)
sublist = [0]*longueur
sublist = [ random.randint(0, ELEM-1) for k in sublist ]
l.append(sublist)
def test_elem_sublist_1(l, n):
for k in l:
if n in k:
return True
return False
def test_elem_sublist_2(l, n):
l = list(itertools.chain.from_iterable(l))
return n in l
def test_elem_sublist_3(l, n):
return any(n in sublist for sublist in l)
if __name__ == "__main__":
t1 = time.time()
for k in range(100):
test_elem_sublist_1(l, ELEM)
ajout_sublist(l)
t2 = time.time()
print("t2-t1 : ", t2-t1)
t3 = time.time()
for k in range(100):
test_elem_sublist_2(l, ELEM)
ajout_sublist(l)
t4 = time.time()
print("t4-t3 : ", t4-t3)
t5 = time.time()
for k in range(100):
test_elem_sublist_3(l, ELEM)
ajout_sublist(l)
t6 = time.time()
print("t6-t5 : ", t6-t5)