Skip to content

Instantly share code, notes, and snippets.

@e-dreyer
Created August 2, 2023 14:39
Show Gist options
  • Save e-dreyer/2e8a0c5d10522bd7860dff946f07ad0c to your computer and use it in GitHub Desktop.
Save e-dreyer/2e8a0c5d10522bd7860dff946f07ad0c to your computer and use it in GitHub Desktop.
Splitting dictionaries into separate values with zip
# Three dictionaries with the same structure
dict1 = {'a': 1, 'b': 2, 'c': 3}
dict2 = {'a': 4, 'b': 5, 'c': 6}
dict3 = {'a': 7, 'b': 8, 'c': 9}
# Using zip and dictionary comprehension to extract the values
values_list = [[dict1[key], dict2[key], dict3[key]] for key in dict1.keys()]
print(values_list)
# Output
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment