Ponytech

Technology for ponies

Jun 17, 2013

Check all items in a list are contained in an other list

In some code I wrote today I needed a way to check that all items in a list are contained in an other list. And I came up with a one-liner I found useful enough for sharing :

>>> big_list = [1,2,3]
>>> small_list = [1,3]
>>> all([i in big_list for i in small_list])
True
>>> small_list = [1,4]
>>> all([i in big_list for i in small_list])
False