Skip to content

Instantly share code, notes, and snippets.

@js51
Created June 7, 2021 06:44
Show Gist options
  • Select an option

  • Save js51/d079ac509b9149cfa8f7f1bf18507ffa to your computer and use it in GitHub Desktop.

Select an option

Save js51/d079ac509b9149cfa8f7f1bf18507ffa to your computer and use it in GitHub Desktop.
Flatten a dictionary (eg for plotting)
dictionary = { 'a': [1,3,8], 'b': [1,2,4,7], 'c': [5,6,8] }
flat_dictionary = [ (k,v) for k in dictionary.keys() for v in dictionary[k]]
x,y = zip(*flat_dictionary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment