Skip to content
Advertisement

Indent-Expected errors while trying to write one-line list comprehension: if-else variants

I am trying to write a list with if-else statements in one line. I’ve followed the instructions in this solution, but I got multiple “indent-Expected” errors.

Here is my code:

JavaScript

The issue in this line:

JavaScript

Advertisement

Answer

continue is a reserved keyword in Python so you are getting the error.

You don’t need a continue to skip element.

Further an if without else is complete in list comprehension.

Based on comments, if you just need to skip elements you can just use an if without an else.

Here is a dummy example to show what you need:

JavaScript
Advertisement