0

Removing item from list value in dictionaries - Python

What would be the best way to remove the value ‘pastrami’ from the following dictionary: sandwiches = {'club':['turkey', 'pastrami', 'ham', 'lettuce', 'tomato'],'meat_feast':['turkey', 'pastrami', 'ham', 'salami'],'plain':['pastrami', 'mustard']}

1st May 2019, 7:58 AM
Dhara
Dhara - avatar
3 Réponses
+ 6
for k in sandwiches: sandwiches[k] = [_ for _ in sandwiches[k] if _ != 'pastrami'] Don't know if it's the best way
1st May 2019, 8:24 AM
Anna
Anna - avatar
0
Thanks everyone, they were very useful 👍
1st May 2019, 5:20 PM
Dhara
Dhara - avatar