Deleting entries
def find_index_post(id):
for i, p in enumerate(my_posts):
if p['id'] == id:
return i@app.delete("/posts/{id}")
def delete_post(id: int):
# Deleting posts
# find the index in the array that requires the ID
# my_posts.pop()
index = find_index_post(id)
my_posts.pop(index)
return {"message": f"post with id {id} was successfully deleted"}


Last updated