naive and unoptimized method:

>>> file = open("text.txt", 'r')
>>> s = file.read()
>>> s
'an elephant jump across the room\nhe met a guy\nthe guy was an moron\n'
>>> s = " "+s.replace('\n', ' ')+" "
>>> s.count(' a ')
1
>>> s.count(' an ')
2
>>> s.count(' the ')
2


On Sat, Nov 7, 2009 at 5:54 AM, surjit khakh <surjitkh...@gmail.com> wrote:

> Write a python program to read a text file named “text.txt” and show the
> number
> of times each article is found in the file. Articles in the English
> language are the
> words “a”, “an”, and “the”.
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to