Back to Freecodecamp

Step 7

curriculum/challenges/english/blocks/learn-lambda-functions-by-building-an-expense-tracker/666ab82c874add3c95145213.md

latest1.3 KB
Original Source

--description--

The pop() method can be used to remove an element from a list. By default, it removes the last element of the list. You can pass an index as the argument to the method, and it will remove the element at the given index.

py
fruits_list = ["cherry", "lemon", "tomato", "apple", "orange"]

fruits_list.pop(2)

print(fruits_list) # ["cherry", "lemon", "apple", "orange"]

In this case, fruits_list.pop(2) removes the element at index 2 of the list.

Use pop() to remove the last element from my_list, then print my_list.

--hints--

You should use pop().

js
({
    test: () => runPython(`
    assert len(_Node(_code).find_calls('pop')) > 0
    `)
})

my_list should be [0, 1, 2].

js
({
    test: () => runPython(`
    assert my_list == [0, 1, 2]
    `)
})

You should print my_list after using pop().

js
({
    test: () => runPython(`
    code = _Node(_code)
    assert(
        any(
            code.is_ordered(pop, 'print(my_list)') for pop in ['my_list.pop()', 'my_list.pop(3)']
        )
    )
    `)
})

--seed--

--seed-contents--

py
--fcc-editable-region--
my_list = [1, 2]

my_list.append(3)
print(my_list)

print(my_list[0])

my_list[0] = 0
print(my_list)

my_list.insert(1, 1)
print(my_list)


--fcc-editable-region--