I'm trying to create a list with even numbers showing as they are and odd numbers showing as "odd".
Here is the code I am trying.
lst = [if x % 2 == 0 else 'odd' for x in range(11)]
I expected to get something like this
[0, "odd", 2, "odd", 4, "odd", 6, "odd", 8, "odd", 10]
But I keep getting SyntaxError exception:
>>> lst = [if x % 2 == 0 else 'odd' for x in range(11)]
  File "<stdin>", line 1
    lst = [if x % 2 == 0 else 'odd' for x in range(11)]
            ^
SyntaxError: invalid syntax
What am I doing wrong?
 
     
     
     
    