PYTHON Count lines, words and characters in text file

PYTHON Count lines, words and characters in text file

SIMPLECODE

8 лет назад

85,641 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Alice West
Alice West - 05.01.2023 15:38

I wish i found this 2 hours ago! thank you!

Ответить
augi blutz
augi blutz - 29.08.2022 17:31

It might be a REAL GOOD IDEA to post the code

Ответить
Shubham Dubey
Shubham Dubey - 19.06.2022 16:02

Bro it is very blured in 720p, plz tell me what I'd written after last line, print"lines:....? i\nWords

Ответить
PRASHANA BALAJI
PRASHANA BALAJI - 14.05.2022 20:24

How to count number of char in csv file without for loop(my delimeter is ,)

Ответить
AR GAMING
AR GAMING - 17.07.2021 20:55

Thank you bro

Ответить
SaMolPP p
SaMolPP p - 10.04.2020 21:55

if the txt file is residing in a different drive and ur python file is sitting in a different location, how you will mention the txt file? should we give the fully qualified path , say D:\testing0410\mytextfile1.txt

Ответить
-Mr.Mohit
-Mr.Mohit - 26.01.2020 21:54

how can i count digits from notepad files ?

Ответить
Learn4Greek
Learn4Greek - 09.01.2020 08:23

Good 👍, I have also create a program to find out the words, vowel, character and space count in a sentence.

Ответить
Darius Programming
Darius Programming - 18.11.2019 13:54

Thanks useful thing.

Ответить
vishal rasaily
vishal rasaily - 07.11.2019 03:05

Whats that character b4 i in the last line

Ответить
Mitch McCann
Mitch McCann - 13.03.2019 07:37

Would this work with a txt document that's in a browser? Like just read a URL that has the text laied out the same as a text document.

Ответить
Kyle
Kyle - 04.03.2019 10:58

how do i use this to find paragraphs

Ответить
ELENA GARCIA DIAZ
ELENA GARCIA DIAZ - 24.02.2019 02:01

//this is no java for using // for comments hahahah (I usually made the same mistake)

Ответить
To N17
To N17 - 31.01.2019 08:14

what soundtrack is this? its nice

Ответить
Sews
Sews - 29.12.2018 21:25

holy shit this is a very fucking informative video
I learned some very useful things. Thanks a lot.

Ответить
All this Origami
All this Origami - 22.12.2018 07:05

why num_lines += 1

Ответить
MJ Ramos
MJ Ramos - 05.12.2018 20:31

you are typing away with out explanation in most lines. NOT COOL ! it does not help.

Ответить
Zulkarnaine
Zulkarnaine - 02.12.2018 23:52

music name please!

Ответить
& Faizan
& Faizan - 18.11.2018 13:09

hello sir,
please make video with audio so we can get better explaination of program,,only seeing codes means that we get it from goolge search also.

Ответить
Matt Hoben Music
Matt Hoben Music - 25.10.2018 01:08

music is rad

Ответить
Michele Helm
Michele Helm - 21.10.2018 22:09

I can't read your code. Can you paste the text file?

Ответить
M.M. 3
M.M. 3 - 20.10.2018 06:38

I muted the video and played Dreamscape by 009 Sound System for nostalgia's sake

Ответить
Lordratatosk1
Lordratatosk1 - 14.08.2018 04:00

I have noticed that some people in the comments section who are copying the video type () instead of ( ). There is a difference and this may be why it is not working properly. The space in between the parentheses tell the program to look for all spaces. This is important because the computer recognizes words by the spaces in between them.

Ответить
Cheese Man
Cheese Man - 13.06.2018 21:41

could you comment the code as text please so I can copy and paste it

Ответить
claudio olivera
claudio olivera - 09.06.2018 18:40

help! 1 how do you solve this problem?
1. (70 points) In a university, students are categorized into four categories. A category of the following table:

Pension category
PENSION CATEGORY
A $ 550
B $ 500
C $ 460
D $ 400

Every six months, the university makes reductions in the pensions of its students to
Starting from the second cycle based on the average according to the following table:
Discount
AVERAGE% DISCOUNT
0 to 3.99 No discount
4 to 7.99 10%
8 to 10 15%

Design a program that determines and shows how much a student will receive a discount on their current pension and their next ancestry.

Ответить
priya davanageri
priya davanageri - 06.03.2018 13:47

how to count num
of files in a folder?

Ответить
ToTheMax
ToTheMax - 30.10.2017 00:10

its great you can type that fast, but you should really slow down the video. Anyone looking at this with minimal experience in python would have to pause repeatedly to keep up

Ответить
Zelios
Zelios - 17.10.2017 02:31

what is the "with" function???

Ответить
Ha Nguyen Manh
Ha Nguyen Manh - 09.07.2017 06:16

how about blank lines if it have alot?

Ответить
Benjamin Rawson
Benjamin Rawson - 05.05.2017 05:40

Better than Idle?

Ответить
Benjamin Rawson
Benjamin Rawson - 05.05.2017 05:35

Which text editor are you using there? It looks nice to use...

Ответить
Fernando Sanabria
Fernando Sanabria - 29.03.2017 06:18

Don't know how active you are now, but I got it to count the amount of words I have. But how do i get it to exclude counting symbols as words? Example, it counts ' - ' and ' -- ' as words.

Ответить
afshana mimi
afshana mimi - 03.03.2017 18:20

Nice video. You may also want to checkout the review of count lines on my blog at edwinreviews. com/count-lines-review/ Thanks, Calvin.

Ответить
ColinTheBruce1
ColinTheBruce1 - 03.04.2016 19:03

def main():
fname = input("Enter filename: ")
infile=open(fname)

numLines = numWords = numChars = 0

for line in infile:
words = line.split()
numLines += 1 - line.count(' ')
numWords += len(words)
numChars += len(line) - line.count(' ')
print("Lines: ", numLines)
print("Words: ", numWords)
print("Characters: ", numChars)


main()

So I've got everything working with what I have above but one of the requirements is to count characters excluding spaces (same for blank lines, but that's working) but for some reason the character count is higher than the number of characters in my .txt file.
File:
black

blue green
pink

yellow orange

1234
4321

It is giving me a count of 46, even though there's clearly less than that...any help would be great!

Ответить
ColinTheBruce1
ColinTheBruce1 - 03.04.2016 07:13

I have what you have but am getting an output of just 0, even though I have a significant amount of characters (trying just characters first)...any help? I've never seen the += before, is that the same as another operation?

Ответить
forgotnglory nonya
forgotnglory nonya - 13.03.2016 21:48

The video was extremely fast but thanks. :)

Ответить
Francios P
Francios P - 03.03.2016 11:45

cool thx ;)

Ответить