Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Noam ossia's challenge HW #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Nomasson
Copy link

@Nomasson Nomasson commented Dec 1, 2019

No description provided.

@Nomasson
Copy link
Author

Nomasson commented Dec 1, 2019

@AviadP


with open('sample.txt', 'r') as file:
data = file.read().replace('\n', '')
print("The content of the file is:\n\n" + data)
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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]
Copy link
Contributor

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))
Copy link
Contributor

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants