MCPcopy Index your code
hub / github.com/plotly/plotly.py / split_dict_by_key_prefix

Function split_dict_by_key_prefix

plotly/shapeannotation.py:275–288  ·  view source on GitHub ↗

Returns two dictionaries, one containing all the items whose keys do not start with a prefix and another containing all the items whose keys do start with the prefix. Note that the prefix is not removed from the keys.

(d, prefix)

Source from the content-addressed store, hash-verified

273
274
275def split_dict_by_key_prefix(d, prefix):
276 """
277 Returns two dictionaries, one containing all the items whose keys do not
278 start with a prefix and another containing all the items whose keys do start
279 with the prefix. Note that the prefix is not removed from the keys.
280 """
281 no_prefix = dict()
282 with_prefix = dict()
283 for k in d.keys():
284 if k.startswith(prefix):
285 with_prefix[k] = d[k]
286 else:
287 no_prefix[k] = d[k]
288 return (no_prefix, with_prefix)

Callers

nothing calls this directly

Calls 1

keysMethod · 0.45

Tested by

no test coverage detected