import random


def weighted_sampler(pop_dict, k=1):
    """randomly sample a dictionary's keys based on weights stored as values example:
       m = {'a':3, 'b':2, 'c':5}
       samps = weighted_sampler(m, k=1000)
       #samps should be a ~ 300, b ~ 200, and c ~ 500
       >>> samps.count('a')
       304
       >>> samps.count('b')
       211
       >>> samps.count('c')
       485
   of course, being a random sampler your results will vary"""
    vals = list(pop_dict.keys())
    weights = [pop_dict[i] for i in vals]
    return random.choices(vals, weights = weights, k=k)