Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions HW python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#my code:

with open('text.txt') as file:
Copy link
Contributor

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

Copy link
Author

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

Copy link
Contributor

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

Copy link
Author

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

List=file.read().split()
wordDict={}
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Author

@morbitton morbitton Dec 3, 2019

Choose a reason for hiding this comment

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

@AviadP I renamed it meaningful - word_counter
and in the second problem i renamed to f_read instead of List

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')



10 changes: 10 additions & 0 deletions text.txt
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