Skip to content

Instantly share code, notes, and snippets.

@RhettTrickett
RhettTrickett / word_count_comparison.py
Created August 13, 2019 19:00
Try catch vs. if else
from timeit import default_timer as time
# Open text file and add each word to a list
with open('file.txt') as f:
lines = [line.strip() for line in f]
words = []
for l in lines:
words.extend(l.split())
@RhettTrickett
RhettTrickett / search_example.py
Created August 10, 2019 17:24
Searching lists vs. sets
import random
import string
from time import time
def random_string(length=20):
chars = string.ascii_letters
return ''.join(random.choice(chars) for i in range(length))