Skip to content
Snippets Groups Projects
Commit 6256d54c authored by sveseli's avatar sveseli
Browse files

utility for dictionary manipulation

parent 4e127fd6
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
import copy
class DictUtility:
@classmethod
def deepCopy(cls, dict, includeKeys=[], excludeKeys=[]):
dict2 = copy.deepcopy(dict)
if len(includeKeys):
for key in dict2.keys():
if not key in includeKeys:
del dict2[key]
elif len(excludeKeys):
for key in excludeKeys:
if dict2.has_key(key):
del dict2[key]
return dict2
#######################################################################
# Testing.
if __name__ == '__main__':
print DictUtility.deepCopy({'k1': '1', 'k2' : '2'}, excludeKeys=['k1'])
print DictUtility.deepCopy({'k1': '1', 'k2' : '2'}, includeKeys=['k1'])
print DictUtility.deepCopy({'k1': '1', 'k2' : '2'})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment