Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Litwin Bartosz
Python_Nauk
Commits
119e1e7d
Commit
119e1e7d
authored
1 year ago
by
Litwin Bartosz
Browse files
Options
Download
Email Patches
Plain Diff
Zadanie 1
parent
832f442d
main
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Project001.py
+48
-0
Project001.py
with
48 additions
and
0 deletions
+48
-0
Project001.py
0 → 100644
View file @
119e1e7d
import
argparse
import
time
import
rich.traceback
from
rich.progress
import
track
#from collections import defaultdict
from
ascii_graph
import
Pyasciigraph
from
ascii_graph
import
colors
import
collections
from
_collections_abc
import
Iterable
collections
.
Iterable
=
Iterable
rich
.
traceback
.
install
()
parser
=
argparse
.
ArgumentParser
(
description
=
'txt word counter.'
)
parser
.
add_argument
(
'filename'
,
help
=
'Name of the file to be read'
)
parser
.
add_argument
(
'-w'
,
'--words'
,
type
=
int
,
default
=
10
,
help
=
'Number of words for histogram'
)
parser
.
add_argument
(
'-l'
,
'--length'
,
type
=
int
,
default
=
0
,
help
=
'Minimal lenght of a word'
)
###
args
=
parser
.
parse_args
()
# Counts = defaultdict(list)
Counts
=
{}
try
:
with
open
(
args
.
filename
,
"r"
,
encoding
=
'utf-8'
)
as
f
:
text
=
f
.
read
()
wordlist
=
text
.
split
()
wordlist
=
wordlist
[
0
:
args
.
words
]
for
word
in
track
(
wordlist
):
if
len
(
word
)
<
args
.
length
:
continue
nword
=
word
.
strip
(
'.,?!'
).
lower
()
Counts
[
nword
]
=
Counts
.
get
(
word
,
0
)
+
1
#print(nword, Counts[nword])
time
.
sleep
(
0.1
)
data
=
list
(
Counts
.
items
())
graph
=
Pyasciigraph
()
for
line
in
graph
.
graph
(
'Word Counts'
,
data
):
print
(
line
)
except
FileNotFoundError
:
print
(
f
"Sorry,
{
args
.
filename
}
not found."
)
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help