Python: load words from file into a set August 27, 2023 by Tarik The strip() method of strings removes whitespace from both ends. set(line.strip() for line in open('filename.txt'))