I've heard that construction {}
works much faster then dict()
. But does that mean I have to write {}
everywhere ?
Asked
Active
Viewed 109 times
0

faoxis
- 1,912
- 5
- 16
- 31
-
FWIW, `{}` is a literal so it can be created when the script is compiled to bytecode, whereas `dict()` calls the `dict` object constructor at runtime. Apart from efficiency considerations, it's generally considered better style to use a literal than an equivalent function / class call. – PM 2Ring Dec 07 '16 at 12:40
1 Answers
0
Just use {} and [] and forget about dict() and list()

Andreas Rau
- 338
- 2
- 11
-
There are plenty good reasons to explicitely use `dict` and `list` (and `set`, `str` or any other builtin type having both a literal and normal syntax). – bruno desthuilliers Dec 07 '16 at 13:09
-
-
@faoxis: building a dict from a list of key:value pairs, building a list from an iterable, etc... – bruno desthuilliers Dec 07 '16 at 13:20
-