1
 d={'developer':'mayank chauhan','avinash shukla','ratan pandey','nikhil arora',
     'maketing':'samrat pandey','ankit kumar','deepak yadav','divyansh pant',
     'research':'kritika singh','aniket mishra','praful pandey','kiran dubey'}

this is the dictionary and this is the list of item i want to search

     list=['mayank','aniket mishra','deepak','kritika singh','aman']

i want a output like this:

key=['developer','maketing','maketing','research']
value=['mayank chauhan','aniket mishra','deepak yadav','kritika singh']

i tried this but it only works if the item in list are exactly same


    for i in list:
        for key, value in d.items():
            if i in value:
                Values.append(i)
                Field.append(key)
    ```

  • a dictionary can contain only key value pairs, so is the value a list of names for each key? – Shijith Dec 03 '19 at 06:24
  • yes that's what it is. – mayank chauhan Dec 03 '19 at 06:52
  • let `lst` be your given list , then use list comprehension , `new = [(key,value) for item in lst for key,values in d.items() for value in values if item in value]` , from this newly created list get `key` as `key = list(set([x for x,_ in new]))` and `value` as `value = [x for _,x in new]` – Shijith Dec 03 '19 at 07:03

0 Answers0