Last active
September 24, 2018 07:12
-
-
Save mustafa-zidan/749f4a4fb8ff29b49cb9d67de4aab030 to your computer and use it in GitHub Desktop.
Code challenge solution for Finway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
# from nltk.corpus import stopwords | |
# stop_words = set(stopwords.words('english')) | |
def word_frequency(file_name): | |
frequency = {} | |
with open(file_name, "r") as lines: | |
for line in lines: | |
# With each line we need to trimmed, stemmed | |
# and stop words skipped | |
for word in line.strip().lower().split(): | |
# if not word in stop_words: | |
count = frequency.get(word,0) | |
frequency[word] = count + 1 | |
frequency_list = frequency.keys() | |
for words in frequency_list: | |
print words, frequency[words] | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='calculate the frequencies of words in a file') | |
parser.add_argument('--input-files', help='input files to calcualte the frequency of') | |
args = parser.parse_args() | |
word_frequency(args.input_files) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the fastest solution to implement within the timeframe. There are a lot of things to improve and here are the things that need to be done from my perspective:
-
,(2d)
orsound".[1]
GIL
will behave in such case. I'd prefer using proper distributed computing platform like spark.