Skip to content

Commit c01d75f

Browse files
authored
Merge pull request #3 from juleskers/patch-1
Also add file-input example to github-readme
2 parents 39adf3c + ba84fa0 commit c01d75f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ m = Map.from_iter(items, path="/tmp/map.fst")
7070
matches = dict(m['clarence':])
7171
assert matches == {'clarence': 2, 'stevie': 3}
7272

73+
# Create a map from a file input, using generators/yield
74+
# The input file must be sorted on the first column, and look roughly like
75+
# keyA 123
76+
# keyB 456
77+
def file_iterator(fpath):
78+
with open(fpath, 'rt') as fp:
79+
for line in fp:
80+
key, value = line.strip().split()
81+
yield key, int(value)
82+
m = Map.from_iter( file_iterator('/your/input/file/'), '/your/mmapped/output.fst')
83+
7384
# re-open a file you built previously with from_iter()
7485
m = Map(path='/path/to/existing.fst')
7586
```

0 commit comments

Comments
 (0)