[Python-ideas] list.copy() for consistency with dict.copy()
anatoly techtonik
techtonik at gmail.com
Tue Jul 23 12:35:27 CEST 2013
More information about the Python-ideas mailing list
Tue Jul 23 12:35:27 CEST 2013
- Previous message: [Python-ideas] A limited exec
- Next message: [Python-ideas] list.copy() for consistency with dict.copy()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Almost everybody knows that you need to copy structures in Python if you need to fork and modify them without consequences. >>> x = [1,2,3] >>> d = x >>> d[1] = 3 >>> x [1, 3, 3] For dict() the fastest way is to use dict.copy() method - http://stackoverflow.com/questions/5861498/fast-way-to-copy-dictionary-in-python For list() it appears that the fastest is to use non-obvious slicing operator: http://stackoverflow.com/questions/2612802/how-to-clone-a-list-in-python The idea is to add list.copy() and make it as fast as slicing. -- anatoly t.
- Previous message: [Python-ideas] A limited exec
- Next message: [Python-ideas] list.copy() for consistency with dict.copy()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list