From the course: Python Data Analysis
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Loading dictionaries from text files - Python Tutorial
From the course: Python Data Analysis
Loading dictionaries from text files
- [Instructor] We begin by loading a dictionary from a file. The repository contains the 1934 English dictionary that is distributed with many Unix systems. We will load it into a list. In Python, we talk of idioms when we think of code constructs that have become the preferred way to achieve a certain goal. One example is looping through all the lines of the text files. For that, we open the file for reading and use the file as a notable in a for loop, which has the result of giving us the lines one by one. For the moment, we will just collect all the lines into a list. We get more than 200,000 words. Let's look at the first 10. Very good. I do see two problems, though, every word ends in the new line character, and also some words are capitalized, which will interfere with our signature scheme. We can fix both issues using Python string methods. To strip leading and trailing white space, including new lines, we can apply strip. And to switch the entire string to lowercase, we use…