'Update a dictionary of item in Python using bottle framework

I am doing crud rest API in Python with bottle framework and I am having trouble updating an item by id in a dictionary. So far I have done create, read, and delete.

Here is my dictionary:

items = [
    {"id": "1", "name": "a", "lastname": "a"},
    {"id": "2", "name": "b", "lastname": "b"},
    {"id": "3", "name": "c", "lastname": "c"}, 
]

And here is my route:

from bottle import get, post, run, redirect, request, response, view, put

@put("/items/<item_id>")
def updated_item(item_id):
    for item in items:
        if item["id"] == item_id:
        new_name = request.forms.get("name")
        new_lastname = request.forms.get("lastname")
            
        #(I need some help here)
    
    return redirect("/items")


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source