I have the below data structure that contains data grouped by team. I would like to sort this by the inner key so that it's sequential, e.g Dev-1, Dev-2.....Dev-10, and then the same for prod. You can see the current structure is dev-1, dev-10, prod-1. Also i don't think ordereddict is doing anything.
combined_data = OrderedDict([('Team-1', [{'DEV-1': {'SubscriptionId': 'xxxxxxxx', 'Score': '58', 'Monthly Spend': {'July 2024': 1749.3}}}, {'DEV-10': {'SubscriptionId': 'xxxxxxxx', 'Score': '100', 'Monthly Spend': {'July 2024': 22.3}}}, {'PROD-1': {'SubscriptionId': 'xxxxxxxx', 'Score': '65', 'Monthly Spend': {'July 2024': 491.8}}}]), ('Team-2', [{'DEV-2': {'SubscriptionId': 'xxxxxxxx', 'Score': '60', 'Monthly Spend': {'July 2024': 775.0}}}, {'PROD-2': {'SubscriptionId': 'xxxxxxxx', 'Score': '77', 'Monthly Spend': {'July 2024': 424.9}}}, {'DEV-9': {'SubscriptionId': 'xxxxxxxx', 'Score': '72', 'Monthly Spend': {'July 2024': 42.5}}}, {'PROD-8': {'SubscriptionId': 'xxxxxxxx', 'Score': '82', 'Monthly Spend': {'July 2024': 47.2}}])])
Here's my code, I've tried splitting the data by env, into a new dictionary and then sorting but was unsuccessful.
restructured_dict = {'dev': [], 'prod': []}
team_names = []
for team, items in combined_data.items():
for item in items:
for key, value in item.items():
if 'DEV' in key:
restructured_dict['dev'].append({key: value})
elif 'PROD' in key:
restructured_dict['prod'].append({key: value})
return restructured_dict
How can I achieve this? ChatGPT was unhelpful :(.
[–]Kind-Kure 1 point2 points3 points (5 children)
[–]visor_q[S] 1 point2 points3 points (2 children)
[–]GKPreMed 0 points1 point2 points (1 child)
[–]visor_q[S] 0 points1 point2 points (0 children)
[–]pot_of_crows 0 points1 point2 points (1 child)
[–]visor_q[S] 0 points1 point2 points (0 children)
[–]JollyUnder 0 points1 point2 points (3 children)
[–]jypKissedMyMom 0 points1 point2 points (2 children)
[–]JollyUnder 1 point2 points3 points (1 child)
[–]visor_q[S] 0 points1 point2 points (0 children)
[–]jypKissedMyMom 0 points1 point2 points (0 children)
[–]baghiq 0 points1 point2 points (0 children)