def test_dedupe_list_of_dicts():
    list_of_dicts_with_duplicates = [{"a": 123, "b": 1234}, {"a": 3222, "b": 1234}, {"a": 123, "b": 1234}]

    expected = [{"a": 123, "b": 1234}, {"a": 3222, "b": 1234}]
    result = dedupe_list_of_dicts(list_of_dicts_with_duplicates)

    assert expected == result
def test_dedupe_list_of_dicts():
    list_of_dicts_with_duplicates = [
        {'a': 123, 'b': 1234},
        {'a': 3222, 'b': 1234},
        {'a': 123, 'b': 1234},
    ]

    expected = [{'a': 123, 'b': 1234}, {'a': 3222, 'b': 1234}]
    result = dedupe_list_of_dicts(list_of_dicts_with_duplicates)

    assert expected == result
示例#3
0
def dedupe_all_lists(obj):
    """Recursively remove duplucates from all lists."""
    squared_dedupe_len = 10
    if isinstance(obj, dict):
        for key, value in obj.items():
            obj[key] = dedupe_all_lists(value)
        return obj
    elif isinstance(obj, (list, tuple, set)):
        new_elements = [dedupe_all_lists(v) for v in obj]
        if len(new_elements) < squared_dedupe_len:
            new_obj = dedupe_list(new_elements)
        else:
            new_obj = dedupe_list_of_dicts(new_elements)
        return type(obj)(new_obj)
    else:
        return obj
示例#4
0
def dedupe_all_lists(obj):
    """Recursively remove duplucates from all lists."""
    squared_dedupe_len = 10
    if isinstance(obj, dict):
        for key, value in obj.items():
            obj[key] = dedupe_all_lists(value)
        return obj
    elif isinstance(obj, (list, tuple, set)):
        new_elements = [dedupe_all_lists(v) for v in obj]
        if len(new_elements) < squared_dedupe_len:
            new_obj = dedupe_list(new_elements)
        else:
            new_obj = dedupe_list_of_dicts(new_elements)
        return type(obj)(new_obj)
    else:
        return obj
示例#5
0
def test_dedupe_list_of_dicts():
    list_of_dicts_with_duplicates = [
        {
            'a': 123,
            'b': 1234
        },
        {
            'a': 3222,
            'b': 1234
        },
        {
            'a': 123,
            'b': 1234
        },
    ]

    expected = [{'a': 123, 'b': 1234}, {'a': 3222, 'b': 1234}]
    result = dedupe_list_of_dicts(list_of_dicts_with_duplicates)

    assert expected == result