Problem 136540 · easy · Phase 01 Prerequisites & Setup

Every Other Song

lists · slicing · step

A shuffled playlist alternates between your songs and a friend's. Write every_other(playlist) that returns a new list containing the songs at positions 0, 2, 4, ... (yours), in order.

Examples

Input:  playlist = ["a", "b", "c", "d", "e"]
Output: ["a", "c", "e"]

Input:  playlist = ["x", "y"]
Output: ["x"]

Constraints

  • 0 <= len(playlist) <= 5000

Goals

  • Select items at even positions
  • Use a slice step or a loop with a stride of 2
Starting Python…