473,598 Members | 3,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

suggestions for using tuples instead of list (or vice versa)

I found out that I am rarely using tuples and almost always lists
because of the more flexible usability of lists (methods, etc.)

To my knowledge, the only fundamental difference between tuples and
lists is that tuples are immutable, so if this is correct, than list
are a superset of tuples, meaning lists can do everything tuples can
do and more.

Is there any advantage for using tuples? Are they "faster"? Consume
less memory? When is it better to use tuples instead of lists and when
better to use lists instead of tuples?

Thorsten
Jul 18 '05 #1
3 2109
Thorsten Kampe wrote:
I found out that I am rarely using tuples and almost always lists
because of the more flexible usability of lists (methods, etc.)

To my knowledge, the only fundamental difference between tuples and
lists is that tuples are immutable, so if this is correct, than list
are a superset of tuples, meaning lists can do everything tuples can
do and more.
Only tuples can be used as dictionary keys.
Is there any advantage for using tuples? Are they "faster"? Consume
less memory?
Not appreciably so in most cases. Certainly not enough to
be a factor in choosing which to use except perhaps in
very rare edge cases.
When is it better to use tuples instead of lists and when
better to use lists instead of tuples?


The canonical answer (which some disagree with) is that you
should use tuples when you have a collection of different
types of items, such as a 'struct' in C would have. Use
lists any other time you want a simple sequential collection
of items.

Use a list for effectively everything else, unless you need
an immutable (tuple) for a dictionary key.

One description of how to look at this that I've found helpful
is something along the lines of "if you can take a slice of
the data and consider it in the same way as the original,
then you should use a list". For example, if you have a set
of fifteen objects over which you plan to iterate, you can
just as well iterate over the first five. If, however, you
have a tuple of (year, month, day, hour, minute, second),
taking the first four items is quite a different thing than
taking all six of them.

-Peter
Jul 18 '05 #2
> Is there any advantage for using tuples? Are they "faster"? Consume
less memory? When is it better to use tuples instead of lists and when
better to use lists instead of tuples?


AFAIK tuples are faster and less memory consuming. I personally prefer them
for e.g. returning multiple values from a function or when I know I won't
need the power of a list. But its largely considered a matter of taste.
Google this newsgroup for a plethora of discussions on this subject....

--
Regards,

Diez B. Roggisch
Jul 18 '05 #3
In article <yl************ ***@thorstenkam pe.de>,
Thorsten Kampe <th******@thors tenkampe.de> wrote:
I found out that I am rarely using tuples and almost always lists
because of the more flexible usability of lists (methods, etc.)


There was an extensive thread on this topic within the last month or
two. Like many threads, it rambled and wandered a bit, but covered the
topic quite well. DAGS for list or tuple in the subject, date <= 2
months, and you should find it.
Jul 18 '05 #4

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

Similar topics

1
4999
by: Valentina Boycheva | last post by:
Thanks for the reply. I already have "Learning Python" from Mark Lutz and David Ascher, which covers 2.3 (I am in 2.4). However, it seems like heavy artillery to me. What I want is, for instance, run a VBScript to get a function output and feed it to the Python script that called it. The reason is that because I feel more comfortable with VBScript and have written a small library of useful utilities, I don't want it to become obsolete. In...
1
3304
by: Dharmendra Singh | last post by:
Hi I'm using .Net(C#) and working on the form(Screen) which have text boxes for both arabic and english data to store. So i want to change the language at run time from arabic to english and vice-versa, when the control moves from one text box to another. Regards Dharmendra
4
4377
by: Chris Gordon-Smith | last post by:
I am tying to call a Pascal function from C++, and vice versa. Does anyone know how to do this, or where detailed information on this topic can be found? For the C++ to Pascal call I have tried declaring the Pascal function as:- extern "C" void PASCALTESTFUNC1(); within my C++ code. However, the linker is giving me an unresolved
1
1975
by: Mr. x | last post by:
.... The second time I am sending this email ... .... I want a good solution, please. .... Thanks :) What I need is moving xml data from client to server & vice versa, but not using xml file. I did something like this : In server (VBScript) : -----------------------------
2
6823
by: Steve - DND | last post by:
Just wondering if anyone out there has any code to convert a plural word to it's singular form and vice versa. Most of our database tables are named in a plural fashion. When we go to create templates to select a single record, we end up with a class name that sounds as if it's a collection instead of just one data object. Just wondering if anyone has a nice workaround. I started working on something, but it quickly turned into a large...
5
1578
by: Ney André de Mello Zunino | last post by:
Hello. I am developing a project in managed C++ for the first time. Things were going fine up until the point I had the need to mix managed and non-managed code. More specifically, what I am trying to have is a MVC-like scheme, where the view is implemented using Windows Forms and the model is composed of a bunch of previously-written non-managed C++ classes. That implies that the view (managed entity) will hold a reference to the model...
5
3329
by: bob | last post by:
Hi Using 2003 - targeting the compact framework (c#), but would like to do most development using the full.net (manually leaving out stuff not in the compact framework). Q. Trying to find a way of converting a project to have builds for both compact and full. Project properties doesn't seem to help Thanks
1
17584
by: pingalkar | last post by:
Hi, In my application, I call one popup winodow by using this link.. <a href="#" onClick="return showWindow('1','XYZ');"> <img src="images/magnifier.gif" ALT="Chemicals" width=18 height=20 border=0> </a> In this showWindow function.... var newWindow = '';
1
1993
by: Maric Michaud | last post by:
Le Tuesday 24 June 2008 07:08:46 swapna mudavath, vous avez écrit : This is not valid xml, there is no commas in attribute list in xml. You could try with minidom if your xml stream isn't too large, else sax parser is to be considered, but minidom is pretty easy to use. Give it a try and come back with more specific questions.
0
7991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8395
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8050
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8265
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5850
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3898
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2412
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 we have to send another system
0
1250
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.