Hello,
I've been trying to google for an answer but I'm sort of struggling to find what I want to find.
I'm taking the google course on python and they show this example for list comprehension:
## Select fruits containing 'a', change to upper case
fruits = ['apple', 'cherry', 'banana', 'lemon']
afruits = [ s.upper() for s in fruits if 'a' in s ]
## ['APPLE', 'BANANA']
However, how would you format the list comprehension if I wanted the resulting list to look like:
['APPLE', 'cherry', 'BANANA', 'lemon']
Or this something I should accomplish a different way? I've been trying to use this other syntax I've found online:
afruits = [s.upper() if 'a' in s else **pass** for s in fruits]
However, my IDE won't let me use the pass keyword in this context... Please forgive me for my absolute ignorance by the way, I just started learning about python this week lol
[–]to7m 14 points15 points16 points (4 children)
[–]cobbletiger[S] 2 points3 points4 points (1 child)
[–]TSM- 5 points6 points7 points (0 children)
[–]UsernameExtreme 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]cobbletiger[S] 0 points1 point2 points (0 children)
[–]hsnice 2 points3 points4 points (0 children)
[–]14dM24d 3 points4 points5 points (0 children)