Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

As Larry said, yes, this is expected behaviour, and has nothing to do with the 
for loop. The purpose of defaultdict is that dict lookups create the entry if 
it doesn't exist:

>>> from collections import defaultdict
>>> d = defaultdict(list)
>>> x = d['any key']
>>> d
defaultdict(<class 'list'>, {'any key': []})


So even though your code loops zero times, you have created a key 'a' with 
value [].

----------
nosy: +steven.daprano

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42310>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to