I've already had a dictionary where len(sample)=5
sample={'a':[1,2],'b':[5,2],'c':[88,3],'d':[63,55],'e':[77,9]}
I want to make a new dictionary which only contains three pairs from sample
. How do I do that?
I've already had a dictionary where len(sample)=5
sample={'a':[1,2],'b':[5,2],'c':[88,3],'d':[63,55],'e':[77,9]}
I want to make a new dictionary which only contains three pairs from sample
. How do I do that?
from random import choice
test = {}
while len(test) < 3:
t = choice(sample.keys())
if t not in test.keys():
test[t] = sample[t]
print(test)