Removing item from list value in dictionaries - Python | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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
2 Respostas
+ 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