Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Create set from List

categories_list = ['animals', 'vegetables', 'fruits']

categories_set = {cat:set() for cat in categories_list}
print(categories_set)
categories_set['animals'].add('cat')
print(categories_set)

Output:

{'animals': set(), 'vegetables': set(), 'fruits': set()}
{'animals': {'cat'}, 'vegetables': set(), 'fruits': set()}