Given the following assignment of a variable: LS = [1, 9, 2, 8, 3, 7, 5, 4]…

2023

Given the following assignment of a variable: LS = [1, 9, 2, 8, 3, 7, 5, 4] print(LS[::-2] + LS[::-2]) What will be the output of the following?

  1. A.

    [5, 3, 2, 1, 9, 8, 7, 4]

  2. B.

    [1, 2, 3, 5, 4, 7, 8, 9]

  3. C.

    [4, 7, 8, 9, 4, 7, 8, 9]

  4. D.

    [9, 8, 7, 4, 5, 3, 2, 1]

Attempted by 1933 students.

Show answer & explanation

Correct answer: C

Key insight: LS[::-2] starts at the last element and takes every second element moving left.

  • Indices chosen (from left-based indexing): 7, 5, 3, 1.

  • Values at those indices: 4, 7, 8, 9 → so LS[::-2] = [4, 7, 8, 9].

  • Concatenate the slice with itself: [4, 7, 8, 9] + [4, 7, 8, 9] = [4, 7, 8, 9, 4, 7, 8, 9].

Final output: [4, 7, 8, 9, 4, 7, 8, 9]

This result matches the provided option text [4, 7, 8, 9, 4, 7, 8, 9].

Explore the full course: Rssb Senior Computer Instructor