Wait... when you unpack a tuple, you're assigning names to the data rather than pulling the data from the tuple?
If I'm understanding your question correctly, yes: When you unpack a tuple, the tuple itself remains intact. Unpacking merely assigns the value of each element of the tuple to a name. This does not change the tuple in any way. If you do this...
# Create a tuple.
person = 'Doe', 'Jane', '01.17.80'
# Print the tuple.
print person
# Now, unpack it.
last, first, birth = person
# Print the unpacked variables
print last, first, birth
# Okay, let's make a change to the last name.
last = 'Mrs. John ' + last
# Now, print those variables again
print last, first, birth
# Now print the tuple again.
print person
...here's what the output looks like:
('Doe', 'Jane', '01.17.80')
Doe Jane 01.17.80
Mrs. John Doe Jane 01.17.80
('Doe', 'Jane', '01.17.80')
Line 1 is the tuple. Line 2 shows the three variables after they are unpacked. Line 3 shows the three variables with the change to last. Line 4 shows that the tuple remains unchanged.
So for a stack and a queue... are these types of lists? If you add something to a list with a stack, does that limit you to only adding other items via stack?
Let's see if I can find a better way to put it: A list is just a sequence or collection of data. Without context, it isn't a stack or a queue.
"Stack" and "queue" are (unnecessarily confusing) terms programmers use to tell other programmers what order they are using to add/remove elements to and from the list. If I'm treating the list as a stack, I remove the last item first. If I'm treating it as a queue, I remove the first item first.
It would make a lot more sense if people used the words in their verb form: "I'm stacking this list" or "I'm queuing this list" because it has to do with the way you treat a list, not with anything that is inherent in the list itself. Does this make more sense?
To answer your second question, no, there are no technical constraints to prevent you switching back and forth between the two behaviors. There may be good logical reasons to treat the data in one way or the other, but that's the sort of thing you have to determine when you're planning a program.
BTW, here's a way to keep the terms straight in your head: For stack, picture a stack of books. Unless you want a real mess, it's best you remove the last (topmost) item and work your way down, right? For a queue, think about a customers in a checkout queue: The first one to arrive at the cashier gets checked out first (unless you want a riot).
no subject
If I'm understanding your question correctly, yes: When you unpack a tuple, the tuple itself remains intact. Unpacking merely assigns the value of each element of the tuple to a name. This does not change the tuple in any way. If you do this...
...here's what the output looks like:
Line 1 is the tuple. Line 2 shows the three variables after they are unpacked. Line 3 shows the three variables with the change to last. Line 4 shows that the tuple remains unchanged.
Let's see if I can find a better way to put it: A list is just a sequence or collection of data. Without context, it isn't a stack or a queue.
"Stack" and "queue" are (unnecessarily confusing) terms programmers use to tell other programmers what order they are using to add/remove elements to and from the list. If I'm treating the list as a stack, I remove the last item first. If I'm treating it as a queue, I remove the first item first.
It would make a lot more sense if people used the words in their verb form: "I'm stacking this list" or "I'm queuing this list" because it has to do with the way you treat a list, not with anything that is inherent in the list itself. Does this make more sense?
To answer your second question, no, there are no technical constraints to prevent you switching back and forth between the two behaviors. There may be good logical reasons to treat the data in one way or the other, but that's the sort of thing you have to determine when you're planning a program.
BTW, here's a way to keep the terms straight in your head: For stack, picture a stack of books. Unless you want a real mess, it's best you remove the last (topmost) item and work your way down, right? For a queue, think about a customers in a checkout queue: The first one to arrive at the cashier gets checked out first (unless you want a riot).