472,992 Members | 3,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 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 4005
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
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.