Sep-29-2018, 02:32 PM
(This post was last modified: Sep-29-2018, 02:32 PM by gruntfutuk.)
The words "I", "like", "eat" and "apples" are not in the file. ("apple" != "apples")
I'm still not understanding. You want to print out every word in the file that was not included in the input?
I've told you how to read all the words from the file into a list called words.
You can do a for loop to step through every word in your sentence list, and for each word, if that word does not appear in the list of words, print it out. You can use the option end='' inside the print function (Python 3) to stop print from ending the line before you want it to, e.g.
(As you are learning Python, I strongly recommend you use Python 3 rather than legacy Python. (Support for Python 2 ends on 1st January 2020.) Generally, I'd suggest that only experienced programmers responsible for maintaining old code, or those with a absolute dependency on a library that has not yet been updated and for which there are no Python 3 compatible alternatives should be using Python 2. Python 3 has many advances, fixed a lot of issues, and is more performant.)
I'm still not understanding. You want to print out every word in the file that was not included in the input?
I've told you how to read all the words from the file into a list called words.
You can do a for loop to step through every word in your sentence list, and for each word, if that word does not appear in the list of words, print it out. You can use the option end='' inside the print function (Python 3) to stop print from ending the line before you want it to, e.g.
print(word, end='')
. It might be easier to generate a new list of the missing words. You can print a comma separated list of strings using the join method: ', '.join(string_list)
inside the print statement.(As you are learning Python, I strongly recommend you use Python 3 rather than legacy Python. (Support for Python 2 ends on 1st January 2020.) Generally, I'd suggest that only experienced programmers responsible for maintaining old code, or those with a absolute dependency on a library that has not yet been updated and for which there are no Python 3 compatible alternatives should be using Python 2. Python 3 has many advances, fixed a lot of issues, and is more performant.)
I am trying to help you, really, even if it doesn't always seem that way