This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # NLTK is a suite of libraries for working with human language data: http://www.nltk.org | |
| # NLTK allows us to access the Carnegie Mellon University Prounouncing Dictionary (cmudict) | |
| # cmudict is a corpus that contains almost 125,000 words mapped to their pronunciations. | |
| # This tiny app was inspired by Lee Vaughn's Impractical Python Projects | |
| import sys | |
| from string import punctuation | |
| from nltk.corpus import cmudict | |
| # load corpus and build dictionary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| def load(name): | |
| """ | |
| This method creates and loads a new journal. | |
| :param name: This base name of the journal to load. | |
| :return: A new journal data structure populated with file data. | |
| """ | |
| data = [] | |
| filename = get_full_pathname(name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Exercise completed as part of Erin Allard's Lynda.com course, | |
| # 'Python Data Structures: Stacks, Queues, and Deques' | |
| class Deque: | |
| """An ADT that resembles both a Stack (LIFO) and a Queue (FIFO). | |
| Items in a deque can be added to and removed from both the back | |
| and front. | |
| Don't reinvent the wheel. More simply, from collections import deque | |
| https://docs.python.org/3/library/collections.html#collections.deque |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Exercise completed as part of Erin Allard's Lynda.com course, | |
| # 'Python Data Structures: Stacks, Queues, and Deques' | |
| class Queue: | |
| """An ADT that stores items in the order in which they | |
| were added. Items are added to the back and removed | |
| from the front - FIFO. | |
| """ | |
| def __init__(self): | |
| self.items = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Exercise completed as part of Erin Allard's Lynda.com course, | |
| # 'Python Data Structures: Stacks, Queues, and Deques' | |
| class Stack: | |
| """An ADT that stores items in the order in which they were | |
| added. Items are added to and removed from the top of the | |
| stack - LIFO. | |
| """ | |
| def __init__(self): | |
| self.items = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Screen scraping information from Weather Underground at https://www.wunderground.com/ is for | |
| # example purposes only. Try the Weather Underground API at https://www.wunderground.com/weather/api | |
| # Project adapted from Michael Kennedy's Python Jumpstart by Building 10 Apps course | |
| # Standard Library | |
| from collections import namedtuple | |
| # Third Party | |
| import requests | |
| from bs4 import BeautifulSoup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import smtplib | |
| import ssl | |
| from email.mime.text import MIMEText | |
| sender = "[email protected]" | |
| receiver = "[email protected]" | |
| password = input("Enter password: ") | |
| text = """\ | |
| Hi! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Learn more about the ICNDb API at: http://www.icndb.com/api/ | |
| # Learn more about the Requests library at: http://docs.python-requests.org/en/master/ | |
| import requests | |
| def get_joke(): | |
| """fetches and prints a random joke""" | |
| url = "http://api.icndb.com/jokes/random" | |
| resp = requests.get(url) | |
| resp.encoding = "utf-8" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # To start, set up a Google form that collects | |
| # first name, last name, and email address from participants, | |
| # then export as a CSV file and store it in the same | |
| # directory as this program | |
| # also, enable less secure apps in gmail before running | |
| # https://support.google.com/accounts/answer/6010255?hl=en | |
| import csv | |
| import smtplib | |
| from random import shuffle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Stopwatch recipe taken from Python Cookbook, 3rd Edition, by David Beazley and Brian K. Jones. | |
| # Page 561: "As a general rule of thumb, the accuracy of timing measurements made with functions | |
| # such as time.time() or time.clock() varies according to the operation system. In contast, | |
| # time.perf_counter() always uses the highest-resolution timer available on the system." | |
| import time | |
| class Timer: | |
| def __init__(self, func=time.perf_counter): | |
| self.elapsed = 0.0 |