I have a dictionary where each key has a list of variable length, eg:
d = {
\'a\': [1, 3, 2],
\'b\': [6],
\'c\': [0, 0]
}
Is there a cle
I'd say this:
random.choice("".join([k * len(d[k]) for k in d]))
This makes it clear that each k in d gets as many chances as the length of its value. Of course, it is relying on dictionary keys of length 1 that are characters....
Much later:
table = "".join([key * len(value) for key, value in d.iteritems()])
random.choice(table)