PYTHON 1. Write a script (not a function!) called ngram_printer.py which asks th
ID: 3676064 • Letter: P
Question
PYTHON
1. Write a script (not a function!) called ngram_printer.py which asks the user to enter a number of characters (call this number n) and then a filename. The script should open the file, display its contents on the screen n characters at a time, and then close the file. If the file doesn't exist, the script should say so, and it should ask the user to enter a different filename. The script should repeatedly ask for a new filename until the user enters a valid filename.
2. Include this:
def is_anagram(string1, string2):
"""returns True if string1 is anagram of string2
string, string -> bool"""
return sorted(string1.lower()) == sorted(string2.lower())
Then define a function called find_anagrams() that takes a string and returns a list of anagrams for that string from the wordlist.txt file. For this assignment, you should use a while loop together with the .readline() method to loop through the contents of the file. When you read in the lines from wordlist.txt, they'll come with a newline character ( ) at the end of each line, and you'll have to deal with that somehow.
wordlist.txt http://homes.soic.indiana.edu/classes/spring2016/csci/a201-ewennstr/wordlist.txt
Explanation / Answer
. 2. The second script with while loop to display the "wordlist.txt "
fp = open('wordlist.txt')
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.