SHARE
TWEET

Untitled

a guest Jun 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import itertools as it
  2.  
  3. d={('a','b'):2,('a','d'):3,('b','e'):4,('b','f'):5}
  4.  
  5. d_items=[[k[0],k[1],v] for k,v in d.items()]
  6.  
  7. new_d=dict((k,dict(tuple(v))) for k,v in it.groupby(d_items,lambda x: x.pop(0)))
  8.  
  9. print(new_d)
  10.  
  11. {'a': {'b': 2, 'd': 3}, 'b': {'e': 4, 'f': 5}}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top