Here is the question:
Implement function processList2(inputList, specialItem, ignoreItems)
that returns a new list that contains all the items of inputList
(and in the original order) except
- Remove any that appear in the list
ignoreItems
- Occurrences of
specialItem
(ifspecialItem
is not inignoreItems
) should become the string"special"
in the new list.
I am trying to create a new list from inputList
using list comprehension. I can get items not in ignoreItems
, but can't seem to figure out how to print 'special' if item == specialItem
.
Here's what I have so far:
def processList2(inputList, specialItem, ignoreItems):
return [item for item in inputList if item not in ignoreItems]
a sample output is something like:
>>> processList2([1,1,2,2], 1, [2])
['special', 'special']
or
>>> processList2([1,2,3,4,True,'dog'], 4, [3,5,4])
[1, 2, True, 'dog']