Editor

Take Turns

#553 · Lists · Beginner · 30 XP · about 5 min

Write take_turns(a, b) that returns a new list made by taking items from the two lists in turns: the first item of a, then the first item of b, then the second item of a, the second of b, and so on.

When one list runs out, the rest of the other list goes on the end, in its own order.

Examples

take_turns([1, 2, 3], ['x', 'y', 'z'])  # returns [1, 'x', 2, 'y', 3, 'z']
take_turns([1, 2, 3, 4], ['x'])         # returns [1, 'x', 2, 3, 4]
take_turns([], [5, 6])                  # returns [5, 6]

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.