Skip to content
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

HW Python - Saar Cohen #11

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

Conversation

SaarCohen93
Copy link

print(x)
print("---------------")
words_in_text = dict()
my_file = open(where_file,"r")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you dont need to open file again, also, file must be closed after ward. best practice is to use "open...with" when working with files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roger that!
will be fixed.

print("Your file text is:")
for x in my_file:
print(x)
print("---------------")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this output is not required

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was just for my debugging, will be deleted.

for key in list(words_in_text.keys()):
print(key, ":", words_in_text[key])
print("---------------")
print (max(words_in_text.values()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check you code again, output is wrong

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now its working with nice output
for highest in list(words_in_text.keys()): if max1 < words_in_text[highest]: max1 = words_in_text[highest] key1 = highest print ("The most recurring word is: ", key1," with ",max1, " times")

@SaarCohen93 SaarCohen93 changed the title HW Python!!! HW Python - Saar Cohen Dec 1, 2019
@SaarCohen93
Copy link
Author

@AviadP
can you check it now? :)

print("Your file text is:")
for x in my_file:
print(x)
print("---------------")
words_in_text = dict()
my_file = open(where_file,"r")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you dont need to open file again

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix.
strange, i was sure that i removed it.

if max1 < words_in_text[highest]:
max1 = words_in_text[highest]
key1 = highest
print ("The most recurring word is: ", key1," with ",max1, " times")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is much better to use f' string. easier to read your code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

max1 = words_in_text[highest]
key1 = highest
print ("The most recurring word is: ", key1," with ",max1, " times")
my_file.close()
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 close file as soon as you done with reading it, or better - use "with...open..."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to with open.

@SaarCohen93
Copy link
Author

@AviadP
:)

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