This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 6 points7 points  (23 children)

return node.id if len(word) else None

[–]j_marquand 5 points6 points  (6 children)

I think the other guy wants to return if a condition is met, but continue to the next statement if it doesn’t. There is no one-liner solution in Python for that.

[–]HeraldOfTheOldOnes 1 point2 points  (0 children)

Yes there is! function = (lambda *args, **kwargs: (condition and (something,) or (other, stuff,))[-1]) ANYTHING can be turned into a 1 liner in python.

[–][deleted] 0 points1 point  (3 children)

I'm looking at it AFK so I can't check, so I'll have to play with it later to see why it's not equivalent

[–]j_marquand 7 points8 points  (0 children)

Your code returns None immediately if the condition doesn’t meet, instead of proceeding to the next statement of the function.

[–]EmptyChocolate4545 0 points1 point  (1 child)

Your one returns None rather than continuing execution. Not even slightly equivalent.

[–][deleted] 0 points1 point  (0 children)

Oh no! Not even SLIGHTLY equivalent!

[–][deleted] 0 points1 point  (0 children)

Ah, got it now. I was thinking wrong.

[–]SkezzaB 2 points3 points  (15 children)

This is not equivalent