json
, similar interfaces exist for other formats like yaml, toml, ...
seq.count(item)
returns the number of elements with the specified value
'green banana'.count('na')
returns 2
seq.index(item)
returns the position of the first match
'green banana'.count('na')
returns 8
from google.colab import files
files.download('/content/spec.txt')
text_from_url
)
text_from_url
index
I have prepared a text file extracted from the duolingo wiki for Czech. The file is at skill0.txt (it was made using extract.py --- README, URLs).
skill0.txt
and extract the vocabulary. The result should be a list of dictionaries, with each dictionary representing a word. The dictionary should indicate which lesson a word was in, the Czech word, and a list of English translations. For example, the first word in the first lesson is::
json.dumps
optional parameters: indent =
2
formats is nicely,ensure_ascii = False
allows it to use unicode. It is not necessary for the computer, but it can help you to debug.
❂ If you haved finished everything else, try this
try:
with open('filename.txt') as file:
contents = file.read()
except FileNotFoundError:
print("File not found.")
LAC: Language and the Computer Francis Bond.