Skip to content

anonymous /daily107i.py

Daily Programmer Day #107 Intermediate Challenge
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
Something went wrong with that request. Please try again.