MCPcopy Index your code
hub / github.com/aws/aws-cli / _partition_dict

Function _partition_dict

awscli/text.py:94–117  ·  view source on GitHub ↗
(item_dict, scalar_keys)

Source from the content-addressed store, hash-verified

92
93
94def _partition_dict(item_dict, scalar_keys):
95 # Given a dictionary, partition it into two list based on the
96 # values associated with the keys.
97 # {'foo': 'scalar', 'bar': 'scalar', 'baz': ['not, 'scalar']}
98 # scalar = [('foo', 'scalar'), ('bar', 'scalar')]
99 # non_scalar = [('baz', ['not', 'scalar'])]
100 scalar = []
101 non_scalar = []
102 if scalar_keys is None:
103 # scalar_keys can have more than just the keys in the item_dict,
104 # but if user does not provide scalar_keys, we'll grab the keys
105 # from the current item_dict
106 for key, value in sorted(item_dict.items()):
107 if isinstance(value, (dict, list)):
108 non_scalar.append((key, value))
109 else:
110 scalar.append(str(value))
111 else:
112 for key in scalar_keys:
113 scalar.append(str(item_dict.get(key, '')))
114 remaining_keys = sorted(set(item_dict.keys()) - set(scalar_keys))
115 for remaining_key in remaining_keys:
116 non_scalar.append((remaining_key, item_dict[remaining_key]))
117 return scalar, non_scalar

Callers 1

_format_dictFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected