[QUESTION] Return lists
See original GitHub issueHi there!
First of all, gerat project! Thank You for sharing it!
i’m a somewhat a beginner, i’d like some help if you guys don’t mind. (I couldn’t find another forum for questions)
I’ve managed to read a list of objects inside a json, by passing the body like this:
[
{
"name": "Item name example 1",
"price": 100,
"is_offer": true
},
{
"name": "Item name example 2",
"price": 100,
"is_offer": true
},
{
"name": "Item name example 3",
"price": 100,
"is_offer": true
}
]
The objective of my micro example is to receive a list of Items (the same base class of the API example), do some processing (change price value by a fixed factor) and return that altered list.
this works:
@app.put("/items/{item_id}")
def create_item(item_id: int, items: List[Item]):
return {"total" : len(items)}
and i can iterate trough the list with
for item in items:
but when i try to return the list with
return {items}
i get “TypeError: unhashable type: ‘list’” error.
is there a simple way to return the list? Or i’ll need to create the return string manually?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Top 25 Questions on Python List - Medium
25 questions on lists to enhance your knowledge on python lists. ... s[1:3] -Returns new list containing elements from index 1 till index ......
Read more >Return a list from a function in Python - Stack Overflow
I'm new to python so pardon me if this is a silly question but I'm trying to return a list from a function....
Read more >Solved Return a list containing all pairs of distinct | Chegg.com
Question : Return a list containing all pairs of distinct elements that satisfy the function fn. Note that the pair [1, 1] should...
Read more >FAQ - The Florida Senate
Return to Question List. 4. How can I tell the difference between a House and a Senate bill? House and Senate bills are...
Read more >Python return statement - GeeksforGeeks
A Python program to return multiple. # values from a method using list. # This function returns a list. def fun():. str =...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Awesome @DaviOtero ! 🎉
As always, thanks @euri10 ! 👏 🌮 🍰
You may (or I may misunderstand what you want to do) be mixing response_model and query parameters
response_model
in the route@app.put("/items/{item_id}", response_model=List[Item])
items: List[Item]
part means you want a list of items in the query passed in the put