Pop an Element and Report Both Parts

Easy ⏱ 8 min 86% acceptance ★★★★★ 4.6
Write pop_at(items, index) that removes and returns the element at index using .pop(), then returns a tuple (popped_value, remaining_list). Assume index is always valid.

Examples

Example 1
Input
items = [5, 10, 15, 20], index = 1
Output
(10, [5, 15, 20])
Explanation

.pop(1) removes and returns 10, leaving the rest.

Constraints

  • 1 <= len(items) <= 10^4

Topics

ListsMutation

Companies

OracleDeloitte

Hints

Hint 1

list.pop(index) both removes and returns the value.

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