django_evolution.utils.datastructures

Utilities for working with data structures.

New in version 2.1.

Functions

filter_dup_list_items(items)

Return list items with duplicates filtered out.

merge_dicts(dest, source)

Merge two dictionaries together.

django_evolution.utils.datastructures.filter_dup_list_items(items)

Return list items with duplicates filtered out.

The order of items will be preserved, but only the first occurrence of any given item will remain in the list.

New in version 2.1.

Parameters:

items (list) – The list of items.

Returns:

The resulting de-duplicated list of items.

Return type:

list

django_evolution.utils.datastructures.merge_dicts(dest, source)

Merge two dictionaries together.

This will recursively merge a source dictionary into a destination dictionary with the following rules:

  • Any keys in the source that aren’t in the destination will be placed directly to the destination (using the same instance of the value, not a copy).

  • Any lists that are in both the source and destination will be combined by appending the source list to the destinataion list (and this will not recurse into lists).

  • Any dictionaries that are in both the source and destinataion will be merged using this function.

  • Any keys that are not a list or dictionary that exist in both dictionaries will result in a TypeError.

New in version 2.1.

Parameters:
  • dest (dict) – The destination dictionary to merge into.

  • source (dict) – The source dictionary to merge into the destination.

Raises:

TypeError – A key was present in both dictionaries with a type that could not be merged.