public
anonymous / daily107i.py
Created

Daily Programmer Day #107 Intermediate Challenge

  • Download Gist
daily107i.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.