Hey everyone,

I need some help on some simple Python programming, below is my problem:

Identify numbers or words in any .txt file that aren't listed in a provided .txt file and to output those numbers or words that aren't in the text file one per line, in alphabetical or numerical order.

So I basically get any txt file filled with numbers and words that needs to be checked using a specific txt file to see if those numbers and words are in the txt file. And then Python will print out the words and numbers that it doesn't find in the provided txt file.

If I haven't explained myself good enough, I'll try and make it more clearer.

(Python has to open these txt files and read them) A random words.txt file will be created which python then has to open and read, below is an example:

10
caterpillar
34
hello
74
90
79
abrogation
ghanian
55
mirrored
09

Then using a provided example.txt file that would only contain these characters...

abrogation
ghanian
55
mirrored
09

...we have to create a program to output all the words and numbers that it doesn't find in the example.txt file using the words.txt file in alphabetical and numberical order.

How would I go about doing this?

Hey,

Yea ok I understand, this isn't exactly homework though, I made the problem up to develop problem solving skills. It is similar to some homework we have to do though, but no way near the same.

I suck at problem solving (and programming), so I have no idea where to start.

Do people learn to drive a manual car by themselves? I doubt it, that is why people need to show you how to drive a car, not just say 'do it'. In the same way, it is hard to learn by yourself programming, if no one shows you how to do it. Even reading a tutorial or book, someone is 'showing' you how to program, do you get it?

Could anyone start me off by providing some pseudocode if you don't want to enter in the full code? It would be great!

Edited 6 Years Ago by bbman: n/a

Let me start by stating I have no Python experience at all, but I consider myself a decent problem solver.

I would do something like this...

arrExample (set this as the list from example.txt)
arrWord (set this as the list from words.txt)

loop through all *words* in arrWord
compare each of them to the all of the words in arrExample
if the *word* is in arrExample...
....skip it, it's already there
if NOT---
---add the number/word to the example.txt
--- AND THEN add it to the arrExample array
--- (this way it won't add the same number/word twice)

close your loops...
close your files...
close your arrays...

Hint.

lst_1 = ['b','a','c','2','1','3']
lst_2 = ['a','b','3''1','2']

diff_list = sorted([item for item in lst_1 if not item in lst_2])

Heyeveryone,

Thanks for helping a newbie in need.

bhartman21: that is sensational! I can see that your problem solving skills are superb, that's exactly what I need to do.

So say their are 2 text files, words.txt and few_words.txt...
I need to have Python go through these files...
If a word or number in few_words.txt is also in the text file words.txt...
Skip it...
if NOT (if the word isn't there in the words.txt file)...
Have python to output the words.

How exactly would I do this?

Edited 6 Years Ago by bbman: n/a

You have already stated that you are a newbie. Maybe it's time to admit that you are still a little TOO new for this problem. Go back to the tutorials and learn file manipulation. How to open and read a file (as a list), and how to write to a file. Then maybe a little refresher on iterating through lists. It's great to develop your own problems to help you learn, but keep them within your realm of ability. Good luck on Python learning quest.

This question has already been answered. Start a new discussion instead.