Python: check if one list can be created from another lists

  python, set

I have list of sets:

graphs = [{1, 2, 3}, {4, 5}, {6}]

I have to check if input set can be created as sum of sets inside graphs.
For example:

input1 = {1, 2, 3, 6} # answer - True
input2 = {1, 2, 3, 4} # answer - False, because "4" is only a part of another set, only combinations of full sets are required 

In other words, there are all combinations of sets inside graphs:

{1, 2, 3}
{4, 5}
{6}
{1, 2, 3, 6}
{1, 2, 3, 4, 5}
{4, 5, 6}
{1, 2, 3, 4, 5, 6}

I need to know, if one of these combinations is equal to input.

How should I correctly iterate through graphs elements to get answer? If graphs is bigger, there would be some problems with finding all the combinations.

Source: Python Questions

LEAVE A COMMENT