473,513 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tuple question

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 enough to convert the tuple to a list and do this,
I'm just curious why it is neccesary..
Thanks,

Will McGugan
Jul 18 '05
50 3638
Peter Hansen <pe***@engcorp.com> wrote:
Alex Martelli wrote:
Claiming that you have to have all info in memory before a tuple can be
built is simply wrong -- your previous claim that the info had to be in
a list was even "wronger", sure, but that doesn't make your current
weaker claims correct in the least.


So, back in the original context here... would you agree that
use of a tuple is "quite realistic" (i.e. a technique that will
save significant amounts of memory) when "there is a huge amount
of static data that you need to access quickly"?


A list of N items over-allocates a bit more than 12% slots (N>>2+6 for
large N). As to whether that saving can be all that significant, I have
my doubts -- a typical list or tuple will uniquely hold a different
object per slot, and an object is way larger than a slot -- the saving
is only in slots, since the objects will be around anyway whether held
in a list or tuple. So the overall savings of memory should be a few
percent at most, excepting unlikely cases where many slots of the
container are referring to the same (relatively few) objects, and even
in the best case can't be more than 10% or so. I would not normally
call even 10% a "significant" amount of memory saving.

This has nothing to do with the issue of where you're keeping the data
before building the container, really. You could have plenty of memory
_at the time you're building the container_, towards the start of your
program, and yet be quite interested in having the long-lasting
container eat up as little memory as feasible, in order to leave memory
available for other uses later, in those crunch-times where you know
your program can end up memory-cramped. Unfortunately, the savings
available this way are not big, I believe.
Alex
Jul 18 '05 #51

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

Similar topics

10
5197
by: Carlo v. Dango | last post by:
Hello there. I have a function which as an argument takes a tuple and either returns that tuple or a mutated version of it. The problem is that tuples are imutable, hence I have to create a new...
37
2346
by: Gregor Horvath | last post by:
Hi, >>>type() <type 'list'> >>>type(('1')) <type 'str'> I wonder why ('1') is no tuple????
3
1487
by: Carl J. Van Arsdall | last post by:
From my interpreter prompt: >>> tuple = ("blah") >>> len(tuple) 4 >>> tuple2 = ("blah",) >>> len (tuple2) 1 So why is a tuple containing the string "blah" without the comma of
6
1706
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 example, time.localtime() returns a time.time_struct,...
62
20132
by: John Salerno | last post by:
Yes, silly question, but it keeps me up at night. :) I know it comes from the suffix -tuple, which makes me think it's pronounced as 'toople', but I've seen (at m-w.com) that the first...
2
3475
by: Alan Isaac | last post by:
I am probably confused about immutable types. But for now my questions boil down to these two: - what does ``tuple.__init__`` do? - what is the signature of ``tuple.__init__``? These...
5
7380
by: abcd | last post by:
I wanted to extend tuple but ran into a problem. Here is what I thought would work class MyTuple(tuple): def __init__(self, *args): tuple.__init__(self, args) x = MyTuple(1,2,3,4) That...
2
3751
by: fabian.conrad | last post by:
Hi, sorry for the rather basic question but I've searched everywhere and don't find an answer. I want to call PyObject_CallObject from the Python C-API and pass a tuple I've created from a...
25
4066
by: beginner | last post by:
Hi, I am wondering how do I 'flatten' a list or a tuple? For example, I'd like to transform or ] to . Another question is how do I pass a tuple or list of all the aurgements of a function to...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.