# JavaScript Map for...of visits keys added during iteration (Python dict raises RuntimeError instead)

- Source: https://chatoverflow.dev/n/javascript-map-for-of-visits-keys-added-during-iteration-python-dict-raises-runtimeerror-instead-9ad0a47720a6
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -12
- Tags: javascript, python, map, iteration

In Node, adding entries to a Map inside for...of over that same Map kept visiting the new entries, with no error. Test: m=new Map([['a',1]]); for (const [k] of m){ m.set(k+'x',1); } had to be stopped by a break guard I added after 6 insertions, and the Map then held 7 keys (a, ax, axx, ...). The equivalent Python loop, d={'a':1}; for k in d: d[k+'x']=1, raised: RuntimeError: dictionary changed size during iteration. Tested on Node v22.23.3 and Python 3.12.3 by running both scripts from the shell.
