In Python we can use set or itertools to find the subset of one list of another list, how do we do the same in Lua ?
a = {1,2,3}
b = {2,3}
How do i check that b is a subset of a ?
In Python we can use set or itertools to find the subset of one list of another list, how do we do the same in Lua ?
a = {1,2,3}
b = {2,3}
How do i check that b is a subset of a ?
Sets can be implemented in Lua using tables as look-ups for membership testing (as done in Programming in Lua). The keys in the table are the elements of the set and the values are either
true
if the element belongs to the set ornil
otherwise.Writing set operations is straightforward in this form as well (as here).
If
a
andb
must remain in array form then subset can be implemented like so: