I have a .txt file that contain ten words(for example ten names) and i wanted to know how can i count the number of names, in this case 10. If i use len(names), the console gives me the length of the word, not the number of the names. Thank you
Post what you have tried with code jpeich,read
this.
@
Bass
We try to answer relative simple question like this yourself in the forum.
It can be okay to reefer an answer in other forum in more difficult cases.
The scale is different to "hundreds of thousands of lines" in that thread.
We can all just search Stack Overflow and post link to answer there,
but that's not much effort and not what we want this forum to be about.
You don't need python to count words.
$ echo "We try to answer relative simple question like this yourself in the forum" | wc -w
13
>>> text = """
... spam eggs
... fish
... carrot dog worm
... mouse keyboard history lesson""".split()
>>>
>>> # with open(filename) as text:
...
>>> word_count = 0
>>> for line in text:
... word_count += len(line.split())
...
>>> word_count
10