def sample_dict(d, n=10, use_random=True):
 selected_keys = (random.sample(list(d), min(len(d), n)) if use_random else itertools.islice(iterkeys(d), n))
 return [(key, d[key]) for key in selected_keys]

def sample_dict ( d , n = 10 , use_random = True ) : selected_keys = ( random . sample ( list ( d ) , min ( len ( d ) , n ) ) if use_random else itertools . islice ( iterkeys ( d ) , n ) ) return [ ( key , d [ key ] ) for key in selected_keys ]
pick n items from dictionary d and return them as a list .