-
Notifications
You must be signed in to change notification settings - Fork 11
Add first python file and new text file #13
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
text = open('text.txt', 'r') | ||
d = dict() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variable name should be meaningful |
||
for line in text: | ||
line = line.strip() | ||
line = line.lower() | ||
words = line.split(" ") | ||
|
||
for word in words: | ||
if word in d: | ||
d[word] = d[word] + 1 | ||
else: | ||
d[word] = 1 | ||
for key in list(d.keys()): | ||
print(key, ":", d[key]) | ||
|
||
mostapperdword=max(d,key=d.get) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. according to python style guide, var name should look like this: most_apperd_word |
||
|
||
print (mostapperdword) | ||
print(max(d.values())) | ||
|
||
print(f'The word that returns most times in the text file is: ' +mostapperdword+ ' and it returns ' ,max(d.values())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Mango banana apple pear | ||
Banana grapes strawberry | ||
Apple pear mango banana | ||
Kiwi apple mango strawberry | ||
mango |
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.
opened file need to closed. best practice is to use "with...open..."