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

Function to_tuple

src/packagedcode/models.py:175–192  ·  view source on GitHub ↗

Return a tuple of basic Python values by recursively converting a mapping and all its sub-mappings. For example:: >>> to_tuple({7: [1,2,3], 9: {1: [2,6,8]}}) ((7, (1, 2, 3)), (9, ((1, (2, 6, 8)),)))

(collection)

Source from the content-addressed store, hash-verified

173
174
175def to_tuple(collection):
176 """
177 Return a tuple of basic Python values by recursively converting a mapping
178 and all its sub-mappings.
179 For example::
180 >>> to_tuple({7: [1,2,3], 9: {1: [2,6,8]}})
181 ((7, (1, 2, 3)), (9, ((1, (2, 6, 8)),)))
182 """
183 if isinstance(collection, dict):
184 collection = tuple(collection.items())
185 assert isinstance(collection, (tuple, list))
186 results = []
187 for item in collection:
188 if isinstance(item, (list, tuple, dict)):
189 results.append(to_tuple(item))
190 else:
191 results.append(item)
192 return tuple(results)
193
194
195party_person = 'person'

Callers 2

to_tupleMethod · 0.85
merge_sequencesFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected