Created
December 21, 2012 02:08
-
-
Save anonymous/4350227 to your computer and use it in GitHub Desktop.
Daily Programmer Day #107 Intermediate Challenge
This file contains 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 random | |
letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', ' '] | |
word_list = [] | |
word_lengths = [] | |
text_file = "whatever.txt" | |
f = open(text_file, 'r') | |
for line in f: | |
line = line.replace("\r\n", "").strip() | |
word_list.append(line) | |
word_lengths.append(len(line)) | |
max_word_length = max(word_lengths) | |
iteration_count = 0 | |
word_count = 0 | |
word = "" | |
#stops it at 20 words, so we're not here all day | |
while word_count < 20: | |
iteration_count+=1 | |
random_letter = letters[random.randint(0,len(letters)-1)] | |
if random_letter == " ": | |
for x in word_list: | |
if x == word: | |
print word | |
word_count+=1 | |
word = "" | |
else: | |
#word is longer than the max word length, start a new word (saves time) | |
if len(word)>max_word_length: | |
word = "" | |
else: | |
word += random_letter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment