>>> cache = {}
>>> cache['1'] = 'long string'
>>> cache['2'] = 'very long string'
>>> buffer = {}
>>> buffer['1'] = cache['1']
>>> del cache['1']
>>> buffer['2'] = cache['2']
>>> del cache['2']
>>> cache
{}
>>> buffer
{'1': 'long string', '2': 'very long string'}
I have two large dictionaries(i.e. cache and buffer). Periodically, I need to move the content from cache
to buffer
and delete the copied item from cache
.
Does Python offer similar function to C++11 std::move so that I don't have to make an extra copy of the item which will be removed later?
Updated based on comments from @JETM
>>> cache = {}
>>> cache['1'] = 'long string2'
>>> buffer['1'] = cache['1']
>>> id(buffer['1'])
139639957636576
>>> id(cache['1'])
139639957636576
>>> del cache['1']
>>> id(buffer['1'])
139639957636576
It looks like the value of cache['1'] is NOT copied into buffer['1'].