472,328 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

tuple.index() and tuple.count()

Before the inevitable response comes, let me assure you I've read
through the posts from Guido about this. 7 years ago Guido clearly
expressed a displeasure with allowing these methods for tuple. Let me
lay out (in a fresh way) why I think we should reconsider.

1) It's counterintuitive to exclude them: It makes very little sense
why an indexable data structure wouldn't have .index() as a method. It
makes even less sense to not allow .count()
2) There's no technical reason (that I'm aware of) why these can't be
3) It does not (contrary to one of Guido's assertions) require any
relearning of anything. It's a new method that could be added without
breaking any code whatsoever (there isn't even a UserTuple.py to
4) The additional documentation is relatively minute (especially since
it could be copied and pasted virtually verbatim from the list methods
5) It's MORE Pythonic to do it this way (more intuitive, less
6) It jives with the help file better. One of Guido's many stated
reasons was that tuples are for heterogeneous sequences and lists are
for homogeneous sequences. While this may be hypothetically true, the
help file does not come close to pointing you in this direction nor
does the implementation of the language.

example: "Tuples have many uses. For example: (x, y) coordinate pairs,
employee records from a database, etc. Tuples, like strings, are
immutable: it is not possible to assign to the individual items of a
tuple (you can simulate much of the same effect with slicing and
concatenation, though). It is also possible to create tuples which
contain mutable objects, such as lists." is a quote from the help
file. Not only does it never mention homogeneous vs. heterogeneous but
mentions both immutable and mutable which draws your mind and
attention to that aspect.

While tuples and lists may have different uses based on convention,
there's really only two reasons to ever use a tuple: Efficiency or
dictionary keys (or some similar immutability requirement). The
implementation contains absolutely NOTHING to reinforce the idea that
lists are for homogeneous data. The implementation of the language
contains EVERY indication that tuples are second class citizens only
to be used for those limited functions above (in fact, efficiency
isn't even talked about in the documentation... I pieced that together
from other threads). Tuples could have been implemented as frozenlist
just as easily.

The lack of .index() and .count() appears to be primarily motivated by
a subtle and silent (at least in the documentation) desire to push
towards coding "best practice" rather than for any technical reason.
While I'm certainly not a "change for change sake" kind of guy and I
understand the "bang for your buck" thinking, I'm just not seeing the
rational for stopping this so forcibly. I get the impression that if a
perfect working patch was submitted, Guido might still reject it which
just seems odd to me.

Again, I'm not trying to raise a stink or open old wounds, I just ran
across it in an app, started doing some research and was thoroughly
confused (for the record, I'm using the tuples as dictionary keys and
had a desire to do k.count() for some edit checks and realized I had
to convert the thing to a list first to run count() )
Jun 27 '08 #1
2 5941
never mind... a coworker pointed me to this


apparently they're there in py3k...
Jun 27 '08 #2
On Jun 23, 3:13*pm, hall.j...@gmail.com wrote:
never mind... a coworker pointed me to this


apparently they're there in py3k...
and 2.6
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Will McGugan | last post by:
Hi, Why is that a tuple doesnt have the methods 'count' and 'index'? It seems they could be present on a immutable object. I realise its easy...
by: Steve M | last post by:
Hello, I'm trying to figure out the index position of a tuple member. I know the member name, but I need to know the members index position. I...
by: Rakesh | last post by:
In my Python code fragment, I want to write a code fragment such that the minimum element of a tuple is subtracted from all the elements of a given...
by: groups.20.thebriguy | last post by:
I've noticed that there's a few functions that return what appears to be a tuple, but that also has attributes for each item in the tuple. For...
by: alainpoint | last post by:
Hello, I have got a problem that i can't readily solve. I want the following: I want to create a supertuple that behaves both as a tuple and as...
by: Nick Maclaren | last post by:
Why doesn't the tuple type have an index method? It seems such a bizarre restriction that there must be some reason for it. Yes, I know it's a...
by: Lorenzo Thurman | last post by:
I have tuple which hold a string in tup. I want to get a slice of that string. I thought I would do something like: tup But this fails. How do I...
by: Shafik | last post by:
Hello folks, I am an experienced programmer, but very new to python (2 days). I wanted to ask: what exactly is the difference between a tuple and...
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.