0

Given a dictionary

collision_domain  = {0: [0, 1, 2], 1: [2, 3, 4]}

this code should output domain 0:

search = 1
for dom, node in collision_domain.items():
    if node == search:
        print("domain", dom)

How do we get that?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

1 Answers1

2

What we need to do here is search inside the list on each iteration of the loop.

Note that the search value comes first and then the list. if search in node:

Final Code:

for dom, node in collision_domain.items():
    if search in node:
        print("domain", dom)
Rashid 'Lee' Ibrahim
  • 1,357
  • 1
  • 9
  • 21