Copy dict to a new object

Python -- Posted on May 12, 2020

Copy dict to a new object

              
                def copy_obj(old, excluded_attrs=[]):
    '''
    Returns a new dict with items for copy to a new object
    excluded_attrs is list of attributes that we want to exclude for copy
    '''
    d = {}
    for key, value in old.items():
        if(len(excluded_attrs)>0):
            if key not in excluded_attrs:
                d[key] = value
        else:
            d[key] = value
    return d
                  
   
            

Related Posts