Skip to content

Instantly share code, notes, and snippets.

@nikhilkumarsingh
Created September 22, 2018 11:13
Show Gist options
  • Save nikhilkumarsingh/8099993aa3a7c0ebc31e4a889ce581af to your computer and use it in GitHub Desktop.
Save nikhilkumarsingh/8099993aa3a7c0ebc31e4a889ce581af to your computer and use it in GitHub Desktop.
Randomize dictionary in Python
import random
d = {'a':1, 'b':2, 'c':3, 'd':4}
for key,val in zip(d.keys(), random.sample(list(d.values()), k=len(d.values()))):
d[key] = val
print(d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment