updade from Atlas repo

This commit is contained in:
Luciano Ramalho
2021-05-21 18:56:12 -03:00
parent c518bf851e
commit 8a330d822b
120 changed files with 2190 additions and 1184 deletions

View File

@@ -17,7 +17,7 @@ d1 = dict(DIAL_CODES) # <1>
print('d1:', d1.keys())
d2 = dict(sorted(DIAL_CODES)) # <2>
print('d2:', d2.keys())
d3 = dict(sorted(DIAL_CODES, key=lambda x:x[1])) # <3>
d3 = dict(sorted(DIAL_CODES, key=lambda x: x[1])) # <3>
print('d3:', d3.keys())
assert d1 == d2 and d2 == d3 # <4>
# end::DIALCODES[]

View File

@@ -5,8 +5,8 @@
# tag::INDEX[]
"""Build an index mapping word -> list of occurrences"""
import sys
import re
import sys
WORD_RE = re.compile(r'\w+')
@@ -15,11 +15,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.setdefault(word, []).append(location) # <1>
# print in alphabetical order
# display in alphabetical order
for word in sorted(index, key=str.upper):
print(word, index[word])
# end::INDEX[]

View File

@@ -5,8 +5,8 @@
# tag::INDEX0[]
"""Build an index mapping word -> list of occurrences"""
import sys
import re
import sys
WORD_RE = re.compile(r'\w+')
@@ -22,7 +22,7 @@ with open(sys.argv[1], encoding='utf-8') as fp:
occurrences.append(location) # <2>
index[word] = occurrences # <3>
# print in alphabetical order
# display in alphabetical order
for word in sorted(index, key=str.upper): # <4>
print(word, index[word])
# end::INDEX0[]

View File

@@ -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[]