flashflood.lod¶
List of dict (LOD) module
List of dict class¶
-
class
ListOfDict
[source]¶ Bases:
list
List of dict utility class
-
find
(key, value)[source]¶ Returns the record found by the given key-value pair. if not found, return None
-
add
(rcd, key='key', dupkey='replace')[source]¶ Adds a new record.
Duplicate key (dupkey) operations
- replace - replace existing record with the new one (default)
- update - update exisiting record (dict.update)
- skip - add no record when the key is duplicated
- replace or update will be applied for only the first one found
Parameters:
-
reduce
(key='key', dupkey='update')[source]¶ Removes records with duplicated key
Not appropriate for large data - worst case: O(n^2)
Duplicate key (dupkey) operations
- update - update exisiting record (dict.update)
- skip - add no record when the key is duplicated
Parameters:
-
merge
(rcds, key='key', dupkey='replace')[source]¶ Adds list of records
Parameters: - rcds (list) – List of dict records to be added
- key (str) – Record key
- dupkey (str) – Type of duplicate key operation
(see
ListOfDict.add
)
-
-
LOD
= <class 'flashflood.lod.ListOfDict'>¶ Shorthand of ListOfDict
Non-destructive list of dict functions¶
-
valuelist
(lod, key)[source]¶ Returns list of values which are assigned to the key.
Parameters: - lod –
flashflood.lod.ListOfDict
- key – key
Returns: list of values
Return type: - lod –