mt_metadata.common.list_dict

Created on Wed Nov 16 11:08:25 2022

@author: jpeacock

Classes

ListDict

Hack together an object that acts like a dictionary and list such that a

Module Contents

class mt_metadata.common.list_dict.ListDict(values={})

Hack together an object that acts like a dictionary and list such that a user can get an item by index or key.

This is the first attempt, seems to work, might think about inheriting an OrderedDict and overloading.

copy()

Copy object

keys()
values()
items()
append(obj)

Append an object

Parameters:

obj (TYPE) – DESCRIPTION

Returns:

DESCRIPTION

Return type:

TYPE

remove(key)

remove an item based on key or index

Parameters:

key (TYPE) – DESCRIPTION

Returns:

DESCRIPTION

Return type:

TYPE

extend(other, skip_keys=[])

extend the dictionary from another ListDict object

Parameters:

other (TYPE) – DESCRIPTION

Returns:

DESCRIPTION

Return type:

TYPE

sort(inplace=True)

sort the dictionary keys into alphabetical order

update(other)

Update from another ListDict

pop(key)

pop item off of dictionary. The key must be verbatim

Parameters:

key (string) – key of item to be popped off of dictionary

Returns:

item popped

update_keys()

Update all keys in the ListDict based on the current state of the objects.

This is useful when object IDs have been changed after being added to the ListDict. The method will re-key all objects using their current ID values.

Returns:

A dictionary mapping old keys to new keys for objects that were re-keyed.

Return type:

dict

to_dict(single=False, nested=False, required=False)

need to implement this method

clear()

Clear all items from the ListDict.