[issue42310] for loop creates element in defaultdict

2020-11-10 Thread Steven D'Aprano
Steven D'Aprano 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 k

[issue42310] for loop creates element in defaultdict

2020-11-10 Thread Larry Hastings
Change by Larry Hastings : -- nosy: -larry ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pyth

[issue42310] for loop creates element in defaultdict

2020-11-10 Thread Larry Hastings
Larry Hastings added the comment: Yes. Read the documentation for "defaultdict". In the future, please read the documentation before filing bugs. -- components: -Argument Clinic resolution: -> not a bug stage: -> resolved status: open -> closed type: behavior ->

[issue42310] for loop creates element in defaultdict

2020-11-10 Thread Sandro Barnabishvili
New submission from Sandro Barnabishvili : from collections import defaultdict d = defaultdict(list) for _ in d['a']: pass print(d.keys()) For loop creates element with key 'a'. Is it expected behavior? -- components: Argument Clinic messages: 380661 nosy: larry, sandrobarna priority: