473,498 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

list assignment

In "Learning Python," by Lutz and Ascher, there's a table showing different
assignment statement forms. One form shown is list assignment. The authors
give this as an example:

[spam, ham] = ['yum', 'YUM']

I don't see how this is any different than a tuple unpacking assignment:
a, b = 1, 2
a, b (1, 2) [a, b] = [1, 2]
a, b

(1, 2)

In both instances the names a and b are both mapped to 1 and 2 so why are there
two different forms?

Thanks for any answers.

--
Norvell Spearman
Feb 22 '06 #1
5 1443
> [spam, ham] = ['yum', 'YUM']

I don't see how this is any different than a tuple unpacking assignment:
>>> a, b = 1, 2


It's not different. They are ways of writing the same thing.
Raymond Hettinger

Feb 22 '06 #2
Raymond Hettinger wrote:
[spam, ham] = ['yum', 'YUM']

I don't see how this is any different than a tuple unpacking assignment:
>>> a, b = 1, 2

It's not different. They are ways of writing the same thing.


TMTOWTDI, after all. :)
Feb 22 '06 #3
Raymond Hettinger wrote:
It's not different. They are ways of writing the same thing.


Lutz and Ascher have tuple and list assignment as separate entries in their
assignment statement forms table so I was expecting there to be some
difference; thanks for setting me straight.

--
Norvell Spearman
Feb 22 '06 #4
Jeffrey Schwab wrote:
TMTOWTDI, after all. :)


A bit ironic that that's the official motto of Perl, don't you think?

--
Norvell Spearman
Feb 22 '06 #5
Norvell Spearman <no*****@stenocall.com> writes:
Lutz and Ascher have tuple and list assignment as separate entries in
their assignment statement forms table so I was expecting there to be
some difference; thanks for setting me straight.


In older Python versions there was a difference between list unpacking
and tuple unpacking. The former would only work with lists and the
latter with tuples. With Python 1.5, both were unified into a more
general sequence unpacking, but for backwards compatibility both
syntaxes were kept.

Bernhard

--
Intevation GmbH http://intevation.de/
Skencil http://skencil.org/
Thuban http://thuban.intevation.org/
Feb 23 '06 #6

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

Similar topics

13
2631
by: Santanu Chatterjee | last post by:
Hello everybody, I am very new to python. I have a query about list in python. Suppose I have a list a = ,5,6,7,,11,12] I want to know if there is any simple python facility available that...
10
2153
by: Philippe C. Martin | last post by:
Hi, I'm looking for an easy algorithm - maybe Python can help: I start with X lists which intial sort is based on list #1. I want to reverse sort list #1 and have all other lists sorted...
11
3072
by: C++fan | last post by:
Suppose that I define the following class: class example_class{ public: example_class(); void funtion_1(); void function_2(); protected:
5
2297
by: Darryl B | last post by:
I can not get anywhere on this project I'm tryin to do. I'm not expecting any major help with this but any would be appreciated. The assignment is attached. The problem I'm having is trying to set...
2
2384
by: Barry Hynes | last post by:
G'Day folks, Have been working on this problem for quite some time and still no farther ahead. :( Here is my problem...bare with me i am very green :) I have to implement a Safe List,...
65
4131
by: Steven Watanabe | last post by:
I know that the standard idioms for clearing a list are: (1) mylist = (2) del mylist I guess I'm not in the "slicing frame of mind", as someone put it, but can someone explain what the...
77
16945
by: Ville Vainio | last post by:
I tried to clear a list today (which I do rather rarely, considering that just doing l = works most of the time) and was shocked, SHOCKED to notice that there is no clear() method. Dicts have it,...
3
2699
by: Christian Christmann | last post by:
Hi, reading the output of gprof for one of my projects, I found that the STL list assignment operator consumes a larger fraction of the program's execution time. The exact entry in gprof's...
1
6219
by: David Bilsby | last post by:
All Apologies for cross posing this but I am not sure if this is a VC 8 STL bug or simply an invalid use of the iterator. I have a PCI card access class which basically abstracts a third party...
6
3006
by: Taras_96 | last post by:
Hi everyone, The FAQ at http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.6 states that: "Consider the following constructor that initializes member object x_ using an initialization...
0
7125
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
7004
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
7167
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
7379
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...
0
5464
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,...
1
4915
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...
0
3095
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
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
292
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.