Swap in Python

Previously, I wrote about swap algorithm in C++. Today, I am going to introduce swapping in Python, and I have a feeling that this post won’t be long.

Python

a, b = b, a

What!? That’s it? One line? What was I doing with C++? Yup, It’s just as simple as it seems. However, Python did something behind the scene, and its efficiency is as same as previous Third Variable Swap Algorithm.

Advertisements
Swap in Python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s