0

I have a dictionary like below and I want to get all the values in a dictionary with the same key,currenlty when I say modules[module]I only get the last value?

modules = {'acer.nak':'kaui.nak','acer.nak':'maui.nak','acer.nak':'nihau.nak'}
module = 'acer.nak'
print modules[module]

OUTPUT:

nihau.nak

EXPECTED OUPUT:

['kaui.nak','maui.nak','nihau.nak']
Jeremyapple
  • 253
  • 2
  • 6
  • 20
  • First of all you should understand about python dict, your dict is not a valid one,because dicts cannot have duplicate keys . – Vikas Periyadath Mar 08 '18 at 05:23
  • Although your dict construction doesn't throw any syntax errors, a Python dict can have only ONE value per key, because Python doesn't allow duplicate keys as said by @VikasDamodar above. Maybe what you need is to have a list for the desired key: `{'acer.nak': ['kaui.nak', 'maui.nak', 'nihau.nak']}` – Victor Silva Mar 08 '18 at 05:28

0 Answers0