Link to home
Start Free TrialLog in
Avatar of JohnAutoSales
JohnAutoSales

asked on

Deleting all members of a list that are of a particular type

Hi there,

Let's say I have a list:

foodlist = ['Fruit', 'Vegetable', 'Fish', 'Pasta', 'Rice_', 'Water', 'Meat_', 'Chocolate']

How would I create a new list that contains members of foodlist that DO NOT end in _  ?    (i.e., the new list would have all members of foodlist except for 'Rice_' and 'Meat_')

newList = ['Fruit', 'Vegetable', 'Fish', 'Pasta', 'Water', 'Chocolate']


newList = []
for food in foodlist:
    if food not ?
         newList.append(food)


It's probably really simple, but I am still novicish (a nice new word!) at Python,


Thanks,
John
ASKER CERTIFIED SOLUTION
Avatar of ramrom
ramrom
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial