Reputation: 4510
Which method is better and why?
a = dict()
b = dict()
c = dict()
or
a, b, c = dict(), dict(), dict()
All three dictionaries will have different keys and are for different purpose.
Upvotes: 0
Views: 487
Reputation: 44454
All 3 dictionaries will have different keys and are for different purpose ?
Keep it on different lines -- they are more readable that way. Readability of a python code matters a lot. That being said, you could:
a = {} # or dict(..)
b = {}
c = {}
Note: This doesn't mean you can not do it in a single line. I am guilty of doing it myself.
Update: It seems there are people who prefer an explicit dict()
over implicit {}
. I guess the former is slightly more readable. Personally, I'm someone who'd go out of my way to delete dict()
and replace with {}
whenever I see one.
Upvotes: 1