I am working on Python code to remove certain elements in dictionary of lists.
dict ={'s': ['a','b'],'d': ['c','d'],'g': ['e','f']}
values = ['a','c','f']
list2 ={i:j.remove(value) for i,j in dict.items() for k in j for value in values if value in k}
print(list2)
Below code is working giving expected result. I am facing issue with comprehensions(above mentioned code)
for i,j in dict.items():
for k in j:
for value in values:
if value in k:
j.remove(value)
I am not sure why comprehension is not working. Please help me with efficient way of solving this
Actual Result:
{'s': None, 'd': None, 'g': None}
Expected Result:
{'s': ['b'], 'd': ['d'], 'g': ['e']}