Write a function writeWordsBeginningWithCharToFilech that cr

Write a function writeWordsBeginningWithCharToFile(ch) that creates a new file named \'ch-words\' (e.g. \'hippo-words\' if ch = \'hippo\') containing all the words of wordlist that begin with string ch and one word per line of file.

Solution

def writeWordsBeginningWithCharToFile(ch):
in_file = open(\"wordlist.txt\",\'r\')
out_file = open(\"%s-wordlist.txt\"%(ch),\'w\')
for line in in_file.readlines():
for word in line.split():
if word.startswith(ch):
out_file.write(word.strip())
out_file.write(\'\ \')
#end
in_file.close()
out_file.close()

 Write a function writeWordsBeginningWithCharToFile(ch) that creates a new file named \'ch-words\' (e.g. \'hippo-words\' if ch = \'hippo\') containing all the w

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site