Check Continence python list

0

I would like help with a code.

lista1 = [5, 6, 7]
lista2 = [4, 'a', 9, 5, 6, 7] 

Make sure that list1 (the entire list) is contained in list2

and

lista2 = [4, 9, 5, 'a', 6, 7] 

Do the same check, but now it's negative.

    
asked by anonymous 09.05.2017 / 18:10

1 answer

1

Create two set 's (set of elements without repeats) and use the issubset method.

lista1 = [5, 6, 7]
lista2 = [4, 'a', 9, 5, 6, 7]

set1 = set(lista1)
set2 = set(lista2)

if(set1.issubset(set2)):
    print('lista1 está contida em lista2')
else:
    print('lista1 não está contida em lista2')

See working at repl.it.

    
09.05.2017 / 18:22