SHARE
TWEET

Untitled

a guest Feb 27th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import csv
  2.  
  3. # user input for the file
  4. fileName = input()
  5.  
  6. # dictionary to store words with their frequencies
  7. wordsFrequency = {}
  8.  
  9. # reading the file
  10. with open(fileName, 'r') as csvfile:
  11.     csvreader = csv.reader(csvfile)
  12. # iterating throught each row
  13.     for row in csvreader:
  14.         for word in row:
  15. # checking if word exixt in the dictionary or not if not present then add the word in the dictionary with frequency 1
  16.             if word not in wordsFrequency.keys():
  17.                 wordsFrequency[word] = 1
  18. # else increase the frequency by 1
  19.             else:
  20.                 wordsFrequency[word] += 1
  21.  
  22. # printin the result
  23. for key in wordsFrequency.keys():
  24.     print(key + " " + str(wordsFrequency[key]))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top