Randomly Shuffle Keys and Values in Python DIctionary
Question: Is there a way to randomly shuffle what keys correspond to what values? I have
found random.sample but I was wondering if there was a more pythonic/faster
way of doing this.

Example: `a = {"one":1,"two":2,"three":3}`

Shuffled: `a_shuffled = {"one":2,"two":3,"three":1}`


Answer: 
    In [47]: import random
    
    In [48]: keys = a.keys()
    
    In [49]: values = a.values()
    
    In [50]: random.shuffle(values)
    
    In [51]: a_shuffled = dict(zip(keys, values))
    
    In [52]: a_shuffled
    Out[52]: {'one': 2, 'three': 1, 'two': 3}
    

Or, more pithy would be:

    
    
    In [56]: dict(zip(a.keys(), random.sample(a.values(), len(a))))
    Out[56]: {'one': 3, 'three': 2, 'two': 1}
    

(but I suppose that is the solution you already came up with.)

* * *

Note that although using `random.sample` is pithier, using `random.shuffle` is
a bit faster:

    
    
    import random
    import string
    def using_shuffle(a):
        keys = a.keys()
        values = a.values()
        random.shuffle(values)
        return dict(zip(keys, values))
    
    def using_sample(a):
        return dict(zip(a.keys(), random.sample(a.values(), len(a))))
    
    N = 10000
    keys = [''.join(random.choice(string.letters) for j in range(4)) for i in xrange(N)]
    a = dict(zip(keys, range(N)))
    
    In [71]: %timeit using_shuffle(a)
    100 loops, best of 3: 5.14 ms per loop
    
    In [72]: %timeit using_sample(a)
    100 loops, best of 3: 5.78 ms per loop
    

