-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Noam ossia's challenge HW #12
base: master
Are you sure you want to change the base?
Conversation
|
||
with open('sample.txt', 'r') as file: | ||
data = file.read().replace('\n', '') | ||
print("The content of the file is:\n\n" + data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz use f' string instead,
also, this output is not needed
print("The content of the file is:\n\n" + data) | ||
|
||
|
||
import re |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all imports should be at the head of the file
words = re.sub("[^\w]", " ", data).split() | ||
|
||
for word in words: | ||
from collections import Counter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never use import within a loop
from collections import Counter | ||
word_counts = Counter(words) | ||
|
||
MOword = word_counts.most_common(1)[0][0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should not use this module to solve the challenge. your should write your own algorithm
MOword = word_counts.most_common(1)[0][0] | ||
MOtimes = word_counts.most_common(1)[0][1] | ||
|
||
print("\nThe most occuring word is {} and it occurs {} times".format(MOword,MOtimes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using f' string is best practice for python3, plz use this method
No description provided.