Python Tip #87 (of 365):
Use tuple unpacking to swap references ๐งต
You can use tuple unpacking to swap the values of 2 variables in Python:
x, y = y, x
Outside of feeling clever in an interview, you may NEVER need to do that... but you MIGHT need to do something similar.
Here we're swapping 2 non-variable references that don't happen to be variables:
values[-2], values[-1] = values[-1], values[-2]
That swaps the last 2 items in a sequence.
๐งต (1/2)