I am trying to perform one task using the list comprehension concept. But it is showing the syntax error.
File "<ipython-input-9-f0c31b619ddf>", line 1
m = [i*i for i in x if i>0 else 0]
SyntaxError: invalid syntax
You need to write your if-else code before the for loop. But in your case, you have written after for loop. So you need to modify your code as shown below.
m = [i*i if i>0 else 0 for i in x]
I found a good solution to solve ...READ MORE
but i m getting this ouput:
Enter the ...READ MORE
raw_input fuction is no longer available in ...READ MORE
It's a function annotation.
In more detail, Python 2.x ...READ MORE
You can also use the random library's ...READ MORE
colors = ['red', 'green', ...READ MORE
Enumerate() method adds a counter to an ...READ MORE
You can simply the built-in function in ...READ MORE
This syntax will not allow in all ...READ MORE
Thanks, This answer was helpful. READ MORE
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.