-4

I have the following simple code in python giving SyntaxError: invalid syntax

I want a new list with non zero values.

data = [11,2,0,34,8,4]
new_data = [ if x for x in data  ]
print( new_data )
Saifullah khan
  • 686
  • 11
  • 19

1 Answers1

1

Here is how to do this:

new_data = [x for x in data if x != 0]
Phydeaux
  • 2,795
  • 3
  • 17
  • 35