Quantcast
Channel: A suitable 'do nothing' lambda expression in python? - Stack Overflow
Browsing all 7 articles
Browse latest View live

Answer by Arthur Khazbs for A suitable 'do nothing' lambda expression in python?

In Python 3 you don't even need to define any functions for that. Calling type(None) will return you the NoneType constructor, which you can use for doing nothing: type(None)(). Keep in mind that the...

View Article



Answer by Rafa0809 for A suitable 'do nothing' lambda expression in python?

This is the simplest lambda expression: do_nothing = lambda: None No arguments required and the minimal required return.

View Article

Answer by Kyle Kelley for A suitable 'do nothing' lambda expression in python?

If you truly want a full do nothing function, make sure to take *args and *kwargs. noop = lambda *args, **kwargs: None In all its glorious action >>> noop = lambda *args, **kwargs: None...

View Article

Answer by Thanatos for A suitable 'do nothing' lambda expression in python?

This: def do_nothing(*args): pass is equivalent to: lambda *args: None With some minor differences in that one is a lambda and one isn't. (For example, __name__ will be do_nothing on the function, and...

View Article

Answer by Paul for A suitable 'do nothing' lambda expression in python?

Sometimes lambda functions are used for data transformation, and in that case 'do nothing' means to return the input, i.e. lambda x: x To return none you can write lambda x: None

View Article


A suitable 'do nothing' lambda expression in python?

I sometimes find myself wanting to make placeholder 'do nothing' lambda expressions, similar to saying: def do_nothing(*args): pass But the following syntax is illegal since lambda expressions attempt...

View Article

Answer by Anton Ermakov for A suitable 'do nothing' lambda expression in python?

Besides this expressionlambda *args: Nonethere is another graceful expression using Ellipsis:lambda *args: ...This can also be useful in case the function has no arguments (callback for...

View Article
Browsing all 7 articles
Browse latest View live




Latest Images