-
Notifications
You must be signed in to change notification settings - Fork 11
Python challenge- HW #15
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 2 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,16 @@ | ||
#my code: | ||
|
||
with open('text.txt') as file: | ||
List=file.read().split() | ||
morbitton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
wordDict={} | ||
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. plz follow python style guide for variable names = this one should be "word_dict", but anyway try to chose better variable names, something that describe the purpose of this var 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. @AviadP I renamed it meaningful - word_counter |
||
for word in List: | ||
if word in wordDict: | ||
wordDict[word]+=1 | ||
else: | ||
wordDict[word]=1 | ||
|
||
print(f' the most recurring word in that file: {max(wordDict, key=wordDict.get)}') | ||
print(f'Appears {wordDict[max(wordDict,key=wordDict.get)]} times') | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Hello world | ||
my name is mor | ||
|
||
Hello world | ||
its my first program i write in python | ||
|
||
i do now homework at python | ||
i use at python version python 3.6 | ||
|
||
python |
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.
with...open... context should only include file operation
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.
@AviadP I changed the file mode - read mode
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.
pls use "with..open..." context manager, as explained in class
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.
@AviadP i change at the new file to - with open('text.txt', 'r') as file