Re:Functools – The Power of Higher-Order Functions in Python
by robertlagrant on Friday July 09, 2021 @10:52AM
(#27784288)
> And don't get me started on the pain of trying to build an Ordered Dictionary with a default initial value!
>>> from collections import defaultdict
>>> from datetime import datetime
>>>
>>> d = defaultdict(datetime.now)
>>> d[1], d[2], d[3], d[4], d[0]
(datetime.datetime(2021, 7, 9, 15, 50, 52, 87605), datetime.datetime(2021, 7, 9, 15, 50, 52, 87613), datetime.datetime(2021, 7, 9, 15, 50, 52, 87614), datetime.datetime(2021, 7, 9, 15, 50, 52, 87615), datetime.datetime(2021, 7, 9, 15, 50, 52, 87616))
>>> for k,v in d.items():
... print(k,v)
...
1 2021-07-09 15:50:52.087605
2 2021-07-09 15:50:52.087613
3 2021-07-09 15:50:52.087614
4 2021-07-09 15:50:52.087615
0 2021-07-09 15:50:52.087616
>>>
Seems pretty good to me?
Re:Functools – The Power of Higher-Order Functions in Python
by mixmastamyk on Friday July 09, 2021 @03:44AM
(#27781364)
Like defaultdict? All dicts have been ordered since 3.6.
The comment showing where groipBy, sortBy etc can be found just shows the problem - they are all in different libraries.That's just plain annoying! And don't get me started on the pain of trying to build an Ordered Dictionary with a default initial value!