My data is structured in a way that I ended up creating a nested dictionary in my design like:
my_dict = {"a": {"b": {"c":"I am c"}}}
my_dict["a"]["b"]["c"]
Is it usual! or we have some other better alternatives (using objects!)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is nothing inherently wrong with nested dicts. Anything can be a dict value, and it can make sense for a dict to be one.
A lot of the time when people make nested dicts, their problems could be solved slightly more easily by using a dict with tuples for keys. Instead of accessing a value as
d[a][b][c], then, the value would be accessed asd[a, b, c]. This is often easier to set up and work with.