Hi I'm really new to programming. I want to add 1 (+1) to each item in a list, except for the items that have value = 3. I tried with a for loop:
p = [1,2,3]
p= [x+1 for x in p if x != 3]
print (p)
#[2,3]
But the output is [2,3], so it adds 1 to the first to items but doesn't output the last one. That's not what I want, I wan't it to show all 3 items but don't add anything to those who are = 3.
Then I tried this but still doesn't work:
p = [1,2,3]
p= [x+1 for x!=3 in p]
print (p)
#SyntaxError: invalid syntax