Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Dictionary + File Reading
#1
I have no idea how to do this program.

I have to write a program that creates a dictionary of words, which is stored in a file. Then that program has to read another file to see if words are in the dictionary. The output is how many times the word appears, the length of the word, and how many constants it has.

I have attached the dictionary and article I have been given.

Please help, thank you so much.


Attached Files
.zip   Dictionary+Article.zip (Size: 442.82 KB / Downloads: 110)
Quote
#2
(Nov-15-2016, 03:48 PM)palmtrees Wrote: I have no idea how to do this program.

I have to write a program that creates a dictionary of words, which is stored in a file. Then that program has to read another file to see if words are in the dictionary. The output is how many times the word appears, the length of the word, and how many constants it has.

You need to know how to read/write to/from a file
loop each line by newline
you can get length of a string via builtin len
you can get the constant count of the word by str.count
counting word frequencies
Quote
#3
(Nov-15-2016, 03:48 PM)palmtrees Wrote: I have no idea how to do this program.

I have to write a program that creates a dictionary of words, which is stored in a file. Then that program has to read another file to see if words are in the dictionary. The output is how many times the word appears, the length of the word, and how many constants it has.

I have attached the dictionary and article I have been given.

Please help, thank you so much.

I have to write a program that creates a dictionary of words, which is stored in a file.

From what I see in the attached zip, you have to read a dictionary file and create a "list" of words in a python variable. This "list" is a likely not a "dictionary" in the Python sense but either a plain Python list, or better a Python set.

Then that program has to read another file to see if words are in the dictionary.

So you read the article file, split it on words, and then for each word, check if the word in the the big list (but you don't output that result?)

The output is how many times the word appears, the length of the word, and how many constants it has.

So you have to count the words. So you have to maintain a structure that relates a string (the word you extracted from the article) to the count of its instances. In Python, this is a "dictionary" (where the key is the word, and the value is the count of instances). When you encounter a word you check if it is in the instances-count dictionary, and if so increment the count, otherwise add it to the dictionary with a count of 1. And when you have read the whole article, all the words have become keys in the dictionary. So you can iterate the dictionary keys, and for each: print the key, print the count, print the length, and print the result of a function that will count the consonants in the key.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Weird problem with reading from file and performing calculations pineapple999 1 165 Jul-25-2019, 01:30 AM
Last Post: ichabod801
  Handling IO Error / Reading from file Expel 10 439 Jul-18-2019, 01:21 PM
Last Post: snippsat
  Reading an Unconventional CSV file OzSbk 2 316 May-17-2019, 12:15 PM
Last Post: MvGulik
  how to put text file in a dictionary infected400 2 562 Jan-06-2019, 04:43 PM
Last Post: micseydel
  reading text file and writing to an output file precedded by line numbers kannan 7 1,196 Dec-11-2018, 02:19 PM
Last Post: ichabod801
  Dictionary to .txt or .csv file stanthaman42 9 826 Aug-08-2018, 03:37 PM
Last Post: Vysero
  Reading of structured .mat (matlab) file sumit 2 1,009 May-24-2018, 12:12 PM
Last Post: sumit
  File Reading toxicxarrow 9 1,586 May-07-2018, 04:12 PM
Last Post: toxicxarrow
  reading all lines from a text file seadoofanatic 2 837 Mar-13-2018, 06:05 PM
Last Post: Narsimhachary
  dictionary from file Zatoichi 5 840 Feb-11-2018, 07:15 PM
Last Post: j.crater

Forum Jump:


Users browsing this thread: 1 Guest(s)