0

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?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Yang
  • 1
  • 1

1 Answers1

0
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)
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
palamunder
  • 2,555
  • 1
  • 19
  • 20