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 5 1450
> [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
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. :)
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
Jeffrey Schwab wrote: TMTOWTDI, after all. :)
A bit ironic that that's the official motto of Perl, don't you think?
--
Norvell Spearman
Norvell Spearman <no*****@stenoc all.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/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 would expand the above list
to give
|
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 accordingly.
Any idea is welcome.
|
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:
|
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 up the
class link and tel_list. I set up a class person with strings for
name, town, and number. I just don't know how to set up the classes w/
their methods (constructors and operations). I'm stuck on the
assignment operator and the add and...
|
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, that is derived from the STL class List and
uses exception handling.
| |
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 difference is between these and:
(3) mylist =
|
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, sets have it,
why do lists have to be second class citizens?
|
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 output looks
as follows:
std::list<MyClass*, std::allocator<MyClass*::operator=
(std::list<MyClass*, std::allocator<MyClass* const&) >
|
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
library from the higher level classes. This low level class is used to
allocate locked pages of memory before doing a DMA. The third party
library locks memory and returns a pointer to an internal structure,
which we can simply cast to a (void...
|
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 list: Fred::Fred() : x_(whatever) { }. The
most common benefit of doing this is improved performance. For
example, if the expression whatever is the same type as member
variable x_, the result of the whatever expression is constructed
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |