[Python-bugs-list] [ python-Feature Requests-517371 ] Add .count() method to tuples

noreply@sourceforge.net noreply@sourceforge.net
Thu, 14 Feb 2002 11:33:41 -0800


Feature Requests item #517371, was opened at 2002-02-14 00:21
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=355470&aid=517371&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Nobody/Anonymous (nobody)
Summary: Add .count() method to tuples

Initial Comment:
Tuples have every method afforded to lists except for 
those which mutate the list; however, there is one 
exception:  .count() appears to have been left out 
eventhough it can be well-defined for tuples as well 
as lists.

>>> s = 'the trump'
>>> s.count('t')
2
>>> list(s).count('t')
2
>>> tuple(s).count('t')
Traceback (most recent call last):
  File "<pyshell#12>", line 1, in ?
    tuple(s).count('t')
AttributeError: 'tuple' object has no attribute 'count'


----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2002-02-14 11:33

Message:
Logged In: YES 
user_id=31435

Guido has rejected this idea before, so don't hold your 
breath.  tuples and lists are intended to be used in 
different ways, and it's "a feature" that their differing 
methods push you toward using them as intended.

Note that tuples don't support .index() either, and that's 
also intentional.

Note that you can use the operator.countOf() function on 
tuples (and, in 2.2, on any iterable object).

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=355470&aid=517371&group_id=5470