0

What I've tried:

def is_this_5(x):
  return [True for i in range(0, 1) if x == 5]

However, this returns [True] and even if that could be fixed I'm sure it could be better than what I've got anyways.

1
  • 2
    I'm a bit confused, what made you think you needed a list comprehension? Is there more to your problem that we do not know? Commented Aug 13, 2018 at 4:49

2 Answers 2

7

You can just do

def is_this_5(x):
    return x == 5

as I assume you are trying to return a boolean, and == returns a boolean result.

Sign up to request clarification or add additional context in comments.

Comments

1

You could use lambda:

In [4]: is_five = lambda(x): x == 5

In [5]: is_five(5)
Out[5]: True

In [6]: is_five(6)
Out[6]: False

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.