Rotate Three Variables in One Line

Easy ⏱ 8 min 73% acceptance ★★★★★ 4.9
Implement rotate_left(a, b, c) that returns a 3-tuple where each value has shifted one position to the left circularly — the new first slot holds b's original value, the new second holds c's, and the new third holds a's — computed with Python's tuple packing/unpacking assignment (a, b, c = b, c, a) rather than a temporary variable.

Examples

Example 1
Input
rotate_left(1, 2, 3)
Output
(2, 3, 1)
Explanation

a takes b's value, b takes c's, c takes a's original value.

Example 2
Input
rotate_left('x', 'y', 'z')
Output
('y', 'z', 'x')
Explanation

Works the same way for any hashable values.

Constraints

  • Must use a single tuple-assignment line, no temp variable.

Topics

TuplesVariables & Data Types

Companies

AmazonZomato

Hints

Hint 1

a, b, c = b, c, a evaluates the whole right-hand tuple before rebinding the names.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.