Python: load words from file into a set

后端 未结 6 1991
暗喜
暗喜 2020-12-29 20:14

I have a simple text file with several thousands of words, each in its own line, e.g.

aardvark
hello
piper

I use the following code to load

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 21:18

    To remove only the right hand spaces.

    set(map(str.rstrip, open('filename.txt')))
    

提交回复
热议问题