MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / merge_sequences

Function merge_sequences

src/packagedcode/models.py:1941–1964  ·  view source on GitHub ↗

Return a new list of model objects merging the lists ``list1`` and ``list2`` keeping the original ``list1`` order and discarding duplicates.

(list1, list2, **kwargs)

Source from the content-addressed store, hash-verified

1939
1940
1941def merge_sequences(list1, list2, **kwargs):
1942 """
1943 Return a new list of model objects merging the lists ``list1`` and
1944 ``list2`` keeping the original ``list1`` order and discarding
1945 duplicates.
1946 """
1947 list1 = list1 or []
1948 list2 = list2 or []
1949 merged = []
1950 existing = set()
1951 for item in list1 + list2:
1952 try:
1953 if hasattr(item, 'to_tuple'):
1954 key = item.to_tuple(**kwargs)
1955 else:
1956 key = to_tuple(kwargs)
1957
1958 except Exception as e:
1959 raise Exception(f'Failed to merge sequences: {item}', f'kwargs: {kwargs}') from e
1960
1961 if not key in existing:
1962 merged.append(item)
1963 existing.add(key)
1964 return merged

Callers 1

updateMethod · 0.85

Calls 4

to_tupleFunction · 0.85
to_tupleMethod · 0.80
addMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected