May-06-2019, 06:40 AM
You can combine string method .startswith and list comprehension with conditional to get desired result. This one of the most straightforward translations of spoken language into Python: "give me color for every color in colors which is not starting with letters 'P', 'B', 'T'":
>>> [color for color in colors if not color.startswith(('P', 'B', 'T'))] ['Red', 'Orange', 'Yellow', 'Green', 'Indigo', 'Violet']
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.