updade from Atlas repo
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
# tag::INDEX_DEFAULT[]
|
||||
"""Build an index mapping word -> list of occurrences"""
|
||||
|
||||
import sys
|
||||
import re
|
||||
import collections
|
||||
import re
|
||||
import sys
|
||||
|
||||
WORD_RE = re.compile(r'\w+')
|
||||
|
||||
@@ -16,11 +16,11 @@ with open(sys.argv[1], encoding='utf-8') as fp:
|
||||
for line_no, line in enumerate(fp, 1):
|
||||
for match in WORD_RE.finditer(line):
|
||||
word = match.group()
|
||||
column_no = match.start()+1
|
||||
column_no = match.start() + 1
|
||||
location = (line_no, column_no)
|
||||
index[word].append(location) # <2>
|
||||
|
||||
# print in alphabetical order
|
||||
# display in alphabetical order
|
||||
for word in sorted(index, key=str.upper):
|
||||
print(word, index[word])
|
||||
# end::INDEX_DEFAULT[]
|
||||
|
||||
Reference in New Issue
Block a user