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

home work #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

home work #16

wants to merge 1 commit into from

Conversation

tomer9989
Copy link

No description provided.

@@ -0,0 +1,28 @@
file = open("C:/Users/tomer/PycharmProjects/HomeChallenge3/Readme.txt")
words = open("C:/Users/tomer/PycharmProjects/HomeChallenge3/Readme.txt").read().split()
Copy link
Contributor

Choose a reason for hiding this comment

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

there is no need to open file twice. "file" variable declared adlready

words = open("C:/Users/tomer/PycharmProjects/HomeChallenge3/Readme.txt").read().split()

print(file.read())
print(words)
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 needed

print(words)


def keywithmaxval(d):
Copy link
Contributor

Choose a reason for hiding this comment

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

use '_' between word - should looks like: key_with_max_val
also, argument name should have some meaning, 'd' is not an acceptable argument name



def keywithmaxval(d):
""" a) create a list of the dict's keys and values;
Copy link
Contributor

Choose a reason for hiding this comment

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

docstring should contain:

  1. general description of the function
  2. arguments - brief description and their type
  3. returns - brief description and their type


print("max word is:", (word_count(words)))
print(file.read())
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.

using context manager( with...open...) is much better way to handle files operations. in case program will exit on error, file might remain opened

return keywithmaxval(counts), max(counts.values())


print("max word is:", (word_count(words)))
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 better using "main" function, that calling other functions

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.

None yet

2 participants