Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This can be helpful in some cases, but it's precisely what I sometimes need to avoid, which is protecting a dictionary and having changes affecting only its own scope.

If function A passes a dict to function B, I would like:

1) Function A to keep the dict intact while function B can manipulate its content;

2) Function A can change the dict after passing to B, and B still keep the original copy, unaware of A's later changes.

One way of doing this is by deep copying dictionaries around, but it can easily become a big performance issue.



It sounds like what you really want is an efficient way of copying dictionaries, perhaps copy on write, something like the cowdict [1] project.

[1]: https://pypi.org/project/cowdict/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: