comprehensions logo comprehensions: example

1 2 3 4 5 6 7 8 9
Notes

Let's try and do a small exercise! Turn the code block below into a comprehensions.

old_list = 'abcde'
new_list = []
for i, c in enumerate(old_list):
    if i % 2 == 0:
        if c in 'aeuio':
            char = c.upper()
        else:
            char = c
        new_list.append(char)
new_list
Solution
[c.upper() if c in 'aeuio' else c
  for i, c in enumerate(old_list)
  if i % 2 == 0]