pg.object_utils.try_listify_dict_with_int_keys

Accessible via pg.object_utils.try_listify_dict_with_int_keys.

try_listify_dict_with_int_keys(src, convert_when_sparse=False)[source]

Try to convert a dictionary with consequentive integer keys to a list.

Return type:

Tuple[Union[List[Any], Dict[Any, Any]], bool]

Parameters:
  • src – A dict whose keys may be int type and their range form a perfect range(0, N) list unless convert_when_sparse is set to True.

  • convert_when_sparse – When src is a int-key dict, force convert it to a list ordered by key, even it’s sparse.

Returns:

converted list or src unchanged.