[Tutor] can anyone help me in solving this problem this is urgent

Shashwat Anand anand.shashwat at gmail.com
Sat Nov 7 17:20:20 CET 2009


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 <surjitkhakh at 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 at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091107/b0a28c3a/attachment.htm>


More information about the Tutor mailing list