My question is the same as
except that I would also like the duplicate items to reflect the number of duplicates in the item string itself (in parentheses).
Example input:
myList = ["paper", "Plastic", "aluminum", "PAPer", "TIN", " paper", "glass", "tin", "PAPER", "Polypropylene Plastic"]
The only acceptable output:
myList = ["paper (3)", "Plastic", "aluminum", "TIN (2)", " paper", "glass", "Polypropylene Plastic"]
Notes:
Note that if an item (
"Polypropylene Plastic"
) happens to contain another item ("Plastic"
), I would still like to retain both items.So, the cases can differ, but the item must be a character-for-character match, for it to be removed.
The original list order must be retained.
All duplicates after the first instance of that item should be removed. The original case of that first instance should be preserved, as well as the original cases of all non-duplicate items.
I am looking for the fastest method to accomplish this in Python 2.7.