flashflood.lod

List of dict (LOD) module

List of dict class

class ListOfDict[source]

Bases: list

List of dict utility class

values(key)[source]

Returns record values with the given key

filter(key, value)[source]

Filters by the given key-value pair

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:
  • rcd (dict) – New record to be added
  • key (str) – Record key
  • dupkey (str) – Type of duplicate key operation
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:
  • key (str) – Record key
  • dupkey (str) – Type of duplicate key operation
unique(key='key')[source]

Aliase of reduce(dupkey=”skip”)

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)
join(rcds, key, full_join=False)[source]

Left join records

Parameters:
  • rcds (list) – List of dict records to be joined
  • key (str) – Join key
  • full_join (bool) – If true, do full join (join all records regardless of whether key exists)
delete(key, value)[source]

Removes records which matches the key-value pair

Parameters:
  • key (str) – key
  • value – value
pick(key, value)[source]

Removes a record which matches the key-value pair from the list and return the record.

If no records are found, this returns None.

Parameters:
  • key (str) – key
  • value – value
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:
Returns:

list of values

Return type:

list

filtered(lod, key, value)[source]

Returns filtered records by the key-value pair.

Parameters:
  • key – key
  • value – value
Returns:

filtered records

Return type:

flashflood.lod.ListOfDict