OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
seadasutils.DictUtils Namespace Reference

Functions

def promote_value (mydict, keyregex)
 
def promote_dict (mydict, keyregex)
 
def flatten_dict (mydict)
 
def delete_key (mydict, keyregex)
 
def delete_empty (mydict)
 
def reassign_keys_in_dict (mydict, namekey, valuekey)
 
def allkeys (mydict)
 

Variables

int val = 99
 
string cmd = "promote_value(dict1, 'IN.*')"
 
dictionary dict1 = {'OUTER': {'INNER': val}}
 
dictionary dict2 = {'OUTER': val}
 

Function Documentation

◆ allkeys()

def seadasutils.DictUtils.allkeys (   mydict)
Return list of all unique keys in dictionary.

Definition at line 119 of file DictUtils.py.

◆ delete_empty()

def seadasutils.DictUtils.delete_empty (   mydict)
Remove empty dictionaries from nested dictionary.

mydict = {'OUTER': {'INNER': val}, 'EMPTY': {'EMPTY': {}}}
delete_empty(mydict)
mydict => {'OUTER': {'INNER': val} }

Definition at line 79 of file DictUtils.py.

◆ delete_key()

def seadasutils.DictUtils.delete_key (   mydict,
  keyregex 
)
Remove all keys with name matching keyregex from nested dictionary.

mydict = {'OUTER': {'INNER1': {'INNER2': {'INNER3': val}}}}
delete_key(mydict, '*.2')
mydict => {'OUTER': {'INNER1': {}}}

Definition at line 64 of file DictUtils.py.

◆ flatten_dict()

def seadasutils.DictUtils.flatten_dict (   mydict)
All keys are promoted, as long as a key of the same name does not exist at the upper level.

mydict = {'OUTER': {'INNER1': {'INNER2': {'INNER3': val}}}}
flatten_dict(mydict)
mydict => {'INNER3': val}

Definition at line 45 of file DictUtils.py.

◆ promote_dict()

def seadasutils.DictUtils.promote_dict (   mydict,
  keyregex 
)
A single-item inner dictionary takes the place of its outer key.
(level up)

mydict = {'OUTER': {'INNER': val}}
promote_dict(mydict, 'IN.*')
mydict => {'INNER': val}

Definition at line 26 of file DictUtils.py.

◆ promote_value()

def seadasutils.DictUtils.promote_value (   mydict,
  keyregex 
)
Assign value of a single-item inner dictionary to its outer key.
(cut out the middleman)

mydict = {'OUTER': {'INNER': val}}
promote_value(mydict, 'IN.*')
mydict => {'OUTER': val}

Definition at line 10 of file DictUtils.py.

◆ reassign_keys_in_dict()

def seadasutils.DictUtils.reassign_keys_in_dict (   mydict,
  namekey,
  valuekey 
)
Combine two key/value pairs.

mydict = {'OUTER': {'namekey': 'key', 'valuekey': val}}
reassign_keys_in_dict(mydict, 'namekey', 'valuekey')
mydict => {'OUTER': {'key': val}}

Definition at line 94 of file DictUtils.py.

Variable Documentation

◆ cmd

string cmd = "promote_value(dict1, 'IN.*')"

Definition at line 142 of file DictUtils.py.

◆ dict1

dictionary dict1 = {'OUTER': {'INNER': val}}

Definition at line 143 of file DictUtils.py.

◆ dict2

dictionary dict2 = {'OUTER': val}

Definition at line 144 of file DictUtils.py.

◆ val

int val = 99

Definition at line 140 of file DictUtils.py.