In Python, you can create a list of sets using the list comprehension for the outer list and the set constructor for the inner sets.
In this example,
set1
and set2
using the set
constructor.list_of_sets
using list comprehension and initialize it with the inner sets.set1 = {1, 2, 3}
set2 = {'a', 'b', 'c'}
list_of_sets = [set1, set2]
for s in list_of_sets:
print(s)
{1, 2, 3} {'a', 'b', 'c'}
In this example,
list_of_empty_sets
using list comprehension.list_of_empty_sets = [set(), set()]
for s in list_of_empty_sets:
print(s)
set() set()
In this tutorial, we learned How to create a List of Sets in Python language with well detailed examples.