19. Set comprehension

Set comprehension avoids for loops.

19.1. Don’t do this

1words = ['i', 'like', 'to', 'eat', 'pizza', 'and', 'play', 'tennis']
2
3vocab = set()
4
5for word in words:
6    vocab.add(word)

19.2. Do this

1words = ['i', 'like', 'to', 'eat', 'pizza', 'and', 'play', 'tennis']
2
3vocab = {word for word in words}