473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

TUPLE & LIST

HI,

1) what are the differences between list and tuple?
2) how to concatenate tuple and list? no method, no opérator?
3) im looking the fucking manual, and cant add value in my tuple, when it
already created :/
how to do it?

thx.


Jul 18 '05 #1
9 4052
On Thu, 15 Jan 2004 15:08:42 +0100, in comp.lang.python you wrote:
HI,

1) what are the differences between list and tuple?
A list is a mutable (ie updatable) container for objects; you can add or
remove objects as much as you like. A tuple is an immutable (ie not
updatable) container, which, once created, cannot change.

The general idea is that a tuple is something like a record in Pascal or
a struct in C (without any named members), so the order of its contents
is important. For example, the function localtime of the time module
returns a tuple, whose first member is the year, second member is the
month etc.
OTOH, the order of some list's contents should bear no special meaning;
therefore a list has methods as .sort(), .reverse() etc.

Examples:
Use a list for a list of names.
Use a tuple for (x,y) coordinates in some area.
Use a list of (name,phone,address) tuples for your poor man's address
book which you will implement in python.
2) how to concatenate tuple and list? no method, no op?tor?
Convert either one to the type of the other.

If the final result should be a tuple, do something like:

final_tuple= your_tuple + tuple(your_list)

But you probably want a list, so do something like:

final_list= list(your_tuple) + your_list
3) im looking the fucking manual, and cant add value in my tuple, when it
already created :/
That's the whole idea, like the FM says in
http://www.python.org/doc/current/ref/types.html . A tuple cannot be
changed, therefore it consumes less space than a list and can be used as
a key, say, in a dictionary (unlike a list).
how to do it?


# You can't, but tuples can be concatenated:
a = 1,2,3
b = 4,5,6
print a (1, 2, 3) print b (4, 5, 6) print a+b (1, 2, 3, 4, 5, 6)

# or sliced:
print a[:2]+b[2:] (1, 2, 6)

# or indexed
print "the first member of %s is %s" % (a, a[0])


HTH
--
TZOTZIOY, I speak England very best,
Ils sont fous ces Redmontains! --Harddix
Jul 18 '05 #2

"Yomanium Yoth Taripoät II" <Yo******@Yomanium.com> wrote in message
news:%7xNb.55
1) what are the differences between list and tuple? http://www.python.org/doc/faq/genera...ate-tuple-and-
list-data-types
2) how to concatenate tuple and list? no method, no opérator? listvar + list (tuplevar)
tuple (listvar) + tuplevar
3) im looking the fucking manual, and cant add value in my tuple, when it
already created :/
how to do it?

Try the Python Manual instead:
http://www.python.org/doc/current/li...q-mutable.html
I know it's not always easy to locate the documentation for the builtin
types.

Daniel

Jul 18 '05 #3
On Thursday 15 January 2004 2:08 pm, Yomanium Yoth Taripo� II wrote:
HI,

1) what are the differences between list and tuple?
2) how to concatenate tuple and list? no method, no op�ator?
3) im looking the fucking manual, and cant add value in my tuple, when it
already created :/
how to do it?

thx.


3) is your answer to 1) !
--
James Henderson, Logical Progression Ltd.
http://www.logicalprogression.net/
Jul 18 '05 #4
Hi Yomanium Yoth Taripoät II (cool name!),

Yomanium Yoth Taripoät II wrote:
1) what are the differences between list and tuple?
2) how to concatenate tuple and list? no method, no opérator?
3) im looking the fucking manual, and cant add value in my tuple, when it
already created :/
how to do it?


This question is answered in the FAQ:
http://www.python.org/doc/faq/genera...ist-data-types

Lists and tuples, while similar in many respects, are generally used in
fundamentally different ways. Tuples can be thought of as being similar
to Pascal records or C structs; they're small collections of related
data which may be of different types which are operated on as a group.
For example, a Cartesian coordinate is appropriately represented as a
tuple of two or three numbers.

Lists, on the other hand, are more like arrays in other languages. They
tend to hold a varying number of objects all of which have the same type
and which are operated on one-by-one. For example, os.listdir('.')
returns a list of strings representing the files in the current
directory. Functions which operate on this output would generally not
break if you added another file or two to the directory.

Tuples are immutable, meaning that once a tuple has been created, you
can't replace any of its elements with a new value. Lists are mutable,
meaning that you can always change a list's elements. Only immutable
elements can be used as dictionary keys, and hence only tuples and not
lists can be used as keys.

yours,
Gerrit.

--
198. If he put out the eye of a freed man, or break the bone of a freed
man, he shall pay one gold mina.
-- 1780 BC, Hammurabi, Code of Law
--
PrePEP: Builtin path type
http://people.nl.linux.org/~gerrit/c.../pep-xxxx.html
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/

Jul 18 '05 #5

"Yomanium Yoth Taripoät II" <Yo******@Yomanium.com> wrote in message
news:%7*************@newsr2.u-net.net...
HI,

1) what are the differences between list and tuple?
2) how to concatenate tuple and list? no method, no opérator?
3) im looking the manual, and can't add value in my tuple, when it
already created :/
how to do it?
Tuples are intended to be a quick way of passing
around several heterogenous values. If you find
yourself wanting to do anything to a tuple other than
creating it and accessing members, then you're
trying to do too much. Use a list if the values
are of the same type, or create an object to
hold whatever it is.

John Roth
thx.

Jul 18 '05 #6
Christos TZOTZIOY Georgiou wrote:
Examples:
Use a list for a list of names.
Use a tuple for (x,y) coordinates in some area.
Use a list of (name,phone,address) tuples for your poor man's address
book which you will implement in python.


What if someone moves away?
That is, I think one could better use a mutable type for the address book.

yours,
Gerrit.

--
46. If he do not receive a fixed rental for his field, but lets it on
half or third shares of the harvest, the grain on the field shall be
divided proportionately between the tiller and the owner.
-- 1780 BC, Hammurabi, Code of Law
--
PrePEP: Builtin path type
http://people.nl.linux.org/~gerrit/c.../pep-xxxx.html
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/

Jul 18 '05 #7

Gerrit Holl wrote in message ...
Christos TZOTZIOY Georgiou wrote:
Examples:
Use a list for a list of names.
Use a tuple for (x,y) coordinates in some area.
Use a list of (name,phone,address) tuples for your poor man's address
book which you will implement in python.


What if someone moves away?
That is, I think one could better use a mutable type for the address book.


That's why it's a "poor man's" address book. :)
--
Francis Avila
Jul 18 '05 #8
Yomanium Yoth Taripoät II wrote:
3) im looking the fucking manual, and cant add value in my tuple, when it already created :/

there's a manual for fucking that talks about tuples? sounds fun. do
share.

cheers,

// m

Jul 18 '05 #9
On Thu, 15 Jan 2004 14:18:36 -0500, rumours say that "Francis Avila"
<fr***********@yahoo.com> might have written:

Gerrit Holl wrote in message ...
Christos TZOTZIOY Georgiou wrote:
Examples:
Use a list for a list of names.
Use a tuple for (x,y) coordinates in some area.
Use a list of (name,phone,address) tuples for your poor man's address
book which you will implement in python.


What if someone moves away?
That is, I think one could better use a mutable type for the address book.


That's why it's a "poor man's" address book. :)


Thanks, Francis :)

To Gerrit: if the context was "help me make an address book", I believe
it is obvious I wouldn't suggest what I suggested. It was just an
example of concurrent tuple and list usage, where list stands for
database table and tuple for database row...
--
TZOTZIOY, I speak England very best,
Ils sont fous ces Redmontains! --Harddix
Jul 18 '05 #10

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

Similar topics

2
by: Evan Patterson | last post by:
How do you convert a tuple to a list? Thanks in advance. --------------------------------- Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard
4
by: Sebastien de Menten | last post by:
Hi, Is there a reason to not extend the tuple destructuration in functions to any expression ? For instance, we can: def f(x, y, *tail): return tail + (x,y) f(3,4,5,6) -> (5,6,3,4) or...
7
by: Java and Swing | last post by:
I have a C function which takes an array of long values.. I understand that I can pass a tuple to a C wrapper function and in the C wrapper function have.. int ok = PyArg_ParseTuple(args,...
5
by: Xah Lee | last post by:
suppose i'm going to have a data structure like this: , , , , .... ] should i use (width,height) or ?
7
by: daniel | last post by:
is there any typical usage that shows their difference? thanks daniel
7
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 a list? I'm sure there are some, but I can't...
3
by: Davy | last post by:
Hi all, I am curious about whether there is function to fransform pure List to pure Tuple and pure Tuple to pure List? For example, I have list L = ,] something list2tuple() will have...
0
by: Chris Rebert | last post by:
On Wed, Sep 24, 2008 at 2:02 PM, David Di Biase <dave.dibiase@gmail.comwrote: You'd probably be better off using the 'key' keyword argument to ..sort(), which is made for the Schwartzian...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...
0
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
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
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...

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.