Python: слова загрузки из файла в набор

Перед тем как передать store в get, пройдите через toJS утилиту по mobx. Это должно решить это.

так что ваш один вкладыш будет - _.get(toJS(store), "prop.arr[0].subProp")

больше на toJS здесь - https://mobx.js.org/refguide/tojson.html

28
задан Roee Adler 17 May 2009 в 06:33
поделиться

6 ответов

The strip() method of strings removes whitespace from both ends.

set(line.strip() for line in open('filename.txt'))
49
ответ дан 28 November 2019 в 02:47
поделиться

Just load all file data and split it, it will take care of one word per line or multiple words per line separated by spaces, also it will be faster to load whole file at once unless your file is in GBs

words =  set(open('filename.txt').read().split())
12
ответ дан 28 November 2019 в 02:47
поделиться
my_set = set(map(str.strip, open('filename.txt')))
4
ответ дан 28 November 2019 в 02:47
поделиться

To remove only the right hand spaces.

set(map(str.rstrip, open('filename.txt')))
1
ответ дан 28 November 2019 в 02:47
поделиться
with open("filename.txt") as f:
    mySet = map(str.rstrip, f)

Если вы хотите использовать это в Python 2.5, вам нужен

from __future__ import with_statement
1
ответ дан 28 November 2019 в 02:47
поделиться
with open("filename.txt") as f:
    s = set([line.rstrip('\n') for line in f])
1
ответ дан 28 November 2019 в 02:47
поделиться
Другие вопросы по тегам:

Похожие вопросы: