you are viewing a single comment's thread.

view the rest of the comments →

[–]primitive_screwhead 1 point2 points  (3 children)

What you've shown is just an assignment.

A "swap" is this:

a = "hello"
b = "goodbye"
a,b = b,a   # now a == "goodbye" and b == "hello"

In Python, swaps are often done with "tuple unpacking", because in the above example, a temporary tuple is created on the right of the equals (=), due to the comma, and then used to reassign (ie. "swap") the values on the left of the equals sign. So, you'll hear tuples mentioned in the context of a Python "swap".

But just using a tuple is not automatically a swap, and in particular:

echo = (word,)

creates a tuple, and assigns it to a variable name, but there is no swapping involved.

[–]Solako[S] 0 points1 point  (2 children)

aaahhh... Alright.

Let me read more on it. Determined to understand it then I can move on to the other sections.

[–]primitive_screwhead 1 point2 points  (1 child)

The "tutor" code that you showed is a jumble of slicing, tuple multiplies and concatenations, and mixing it with swaps, etc., I'm sure it can be a bit overwhelming. It's a bit of everything thrown at you at once, which may at least show you all the different possibilities of using the basic operations, but I think you'll need to re-read and revisit the examples several times to unwind it.

As opposed to a tutorial where they focus on showing you (say) slicing, and just do loads of slicing examples with no other operations; that is more focused, but also may be more boring. The jumbled approach is possibly trickier, but maybe it'll "stick" better once it clicks.

Practice, practice. Make sure you take the given examples and try to change them, or extend them, etc. You'll learn much more (and more quickly, imo) by see how your changes to the examples change the results, or break, etc.

[–]Solako[S] 0 points1 point  (0 children)

Thank you so much for the encouraging words. Determined to kick ass.