Dictionary of dictionaries than a list of objects? #39
Replies: 3 comments 4 replies
-
First, thank you for your comment, it's always a pleasure to know your project is used by others for their own projects 😄
It's my first project with FastAPI, and I didn't want to already do some specific tweaks. But now, I know there are some ways to bypass this default behaviour by using custom responses, and adding additional responses in the OpenAPI specs used for the documentation. The Finally, if I do it, I'll probably define a new endpoint for it, in order to avoid breaking changes as I'm not exposing several versions of the API at the same time as of today 🙈 |
Beta Was this translation helpful? Give feedback.
-
I'm not familiar with FastAPI but isn't it possibile? from career_stats[hero_key].append(
{
"category": string_to_snakecase(category_label),
"label": category_label,
"stats": {},
}
)
for stat_row in content_div.find_all("div", class_="stat-item"):
stat_name = stat_row.find("p", class_="name").get_text()
value = {}
value[stat_name] = get_computed_stat_value(stat_row.find("p", class_="value").get_text())
career_stats[hero_key][-1]["stats"][string_to_snakecase(stat_name)] = value
I understand, that sounds good, thanks! |
Beta Was this translation helpful? Give feedback.
-
@davidetacchini The new endpoint is available ! Here is the associated documentation : https://overfast-api.tekrop.fr/#tag/Players/operation/get_player_career_stats_players__player_id__stats_career_get 😉 |
Beta Was this translation helpful? Give feedback.
-
Hi @TeKrop, nice API; can't wait to make the switch for my project and use it in production!
Wouldn't it be better using a dictionary of dictionaries than a list of dictionaries in the following section?
Personally, I think it is better in case someone wants to get a specific category (e.g. "best") without having to iterate through the entire list each time, so the time complexity would be O(1) instead of the actual O(n).
I see that you can have multiple key/value pairs per object by using a list of objects, thus adding more information. However, in this specific case, it's pretty easy to get the
label
out of the key if a dictionary of dictionaries is used by simply formatting it. Thanks for the attention, keep up the good work :)Beta Was this translation helpful? Give feedback.
All reactions