B
Ben Finney
Nick Craig-Wood said:You can also do this with the dict() syntax
As was implied by the plural "these" in "I often use these myself".
Nick Craig-Wood said:You can also do this with the dict() syntax
The irony that, x = (,) produces an error.
Personally I would of thought it would be a better example of an empty
tuple than anything else, but it still isn't that readable.
The use of dict/list/tuple/set seems to stand out a lot better, makes
it readable! Else in a few years you'll have §x§ = !^!()
Or maybe I am going crazy...
...Missing that, I think dict() and set() and
tuple() and list() look better than using {} for the empty dict and
{/} for the empty set and () for empty tuple (or {} for the empty dict
and set() for the empty set).
0.50557906102591232>>> import timeit
>>> timeit.Timer('[]').timeit() 0.22358344426456436
>>> timeit.Timer('list()').timeit() 0.54574505977715049
>>> timeit.Timer('{}').timeit() 0.21328632549668214
>>> timeit.Timer('dict()').timeit()
But this is "performance" in the abstract. It's hardly going to matterBoris said:...Missing that, I think dict() and set() and
tuple() and list() look better than using {} for the empty dict and
{/} for the empty set and () for empty tuple (or {} for the empty dict
and set() for the empty set).
The problem I have with them is in no way the looks, it is that they are not
strictly equivalent as they imply dictionary lookups. Which shows in performance, eg
0.50557906102591232import timeit
timeit.Timer('[]').timeit() 0.22358344426456436
timeit.Timer('list()').timeit() 0.54574505977715049
timeit.Timer('{}').timeit() 0.21328632549668214
timeit.Timer('dict()').timeit()
Before you have any code is exactly the *wrong* time to be considering
performance.
Steve said:But this is "performance" in the abstract. It's hardly going to matterBoris said:The problem I have with them is in no way the looks, it is that they are not...Missing that, I think dict() and set() and
tuple() and list() look better than using {} for the empty dict and
{/} for the empty set and () for empty tuple (or {} for the empty dict
and set() for the empty set).
strictly equivalent as they imply dictionary lookups. Which shows in performance, eg
0.50557906102591232import timeit
timeit.Timer('[]').timeit() 0.223583444264564360.21328632549668214timeit.Timer('list()').timeit() 0.54574505977715049
timeit.Timer('{}').timeit()
timeit.Timer('dict()').timeit()
if you use it once in the initialization of your program, but if it
occurs deep inside a quadruply-nested loop that is executed 10^12 times
it may have an impact on performance.
Before you have any code is exactly the *wrong* time to be considering
performance.
regards
Steve
Boris said:Steve Holden wrote: [...]Before you have any code is exactly the *wrong* time to be considering
performance.
Yeah right, [] and {} are premature optimizations, one should always use list()
or dict() unless one detains figures to justify the more exotic forms
It's about four years since I wrote a program that ran for more than 24
hours.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.