Skip to content

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants