[Tutor] Counting Items in a List

Brad Hudson brad.hudson at gmail.com
Wed Jun 20 17:12:39 CEST 2012


I think this is more of what you ar looking for:

>>> a = 'this is a list with is repeated twice.'
>>> a
'this is a list with is repeated twice.'
>>> alist = a.strip().split()
>>> alist
['this', 'is', 'a', 'list', 'with', 'is', 'repeated', 'twice.']
>>> var='is'
>>> alist.count(var)
2
>>>

On Wed, Jun 20, 2012 at 8:44 AM, Oğuzhan Öğreden <ogreden at gmail.com> wrote:

> Sorry, it seems like I was not clear enough in that statement. I should
> have written something like "counting how many times each word occured"
> insted of "counting words".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120620/5e969e49/attachment.html>


More information about the Tutor mailing list