{"id":14825,"date":"2016-10-03T12:41:11","date_gmt":"2016-10-03T09:41:11","guid":{"rendered":"https:\/\/www.webcodegeeks.com\/?p=14825"},"modified":"2016-10-03T12:41:11","modified_gmt":"2016-10-03T09:41:11","slug":"multi-line-lambdas-python","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/","title":{"rendered":"Multi-Line Lambdas in Python"},"content":{"rendered":"<p>I need to preface all of this with a disclaimer:\u00a0I love Python, but I <i>am<\/i> able to see plenty of faults with it. In this article, I attempt to provide a very roundabout way of working around one of those faults: the lack of multi-line lambdas. This is <i>not<\/i> to say that this is a good solution, but it may be one of the best that we have for certain cases. Try and see if one of the typical workarounds is the best option before settling on this.<\/p>\n<h2>Intro<\/h2>\n<p>Python has one missing feature that actually hurts my idea that Kotlin is a lot like a statically-typed Python: lack of multi-line lambdas; lambdas in Python, as you probably know, are limited to a single expression or statement. There are numerous ways to get around all of this, but none are very satisfying, since they either obfuscate the code or don\u2019t put it in the place that you want it.<\/p>\n<h2>Workarounds<\/h2>\n<p>The first and most obvious workaround is to define a function that does what you want then pass that function in instead of a lambda. This is generally your best bet, and if you name the function well, it can help to actually make the code more clear. But, in some instances, having the code right there would be more helpful than any name.<\/p>\n<p>The next workaround is to try and squeeze your code into one line somehow. In this video of <a href=\"https:\/\/youtu.be\/DsUxuz_Rt8g\">a talk given at PyCon 2016, Oneliner-izer: An Exercise in Constrained Coding<\/a>, Chelsea talks about how it\u2019s technically possible to squeeze any code into a single line (I watched the video a while ago and didn\u2019t actually finish it, so there may be some restrictions that I don\u2019t remember\/didn\u2019t see). To be blunt, this is probably a BAD idea. In simple cases, it may work, but it\u2019ll still likely be too confusing to be maintainable.<\/p>\n<p>In certain circumstances you could also try to combine those lines using <a href=\"https:\/\/nvbn.github.io\/2016\/08\/09\/partial-piping\/\">function piping<\/a> or <a href=\"https:\/\/mathieularose.com\/function-composition-in-python\/\">composition<\/a>. If it\u2019s possible to do this, and everyone in your codebase is kind of into functional programming, then this is probably your best bet. It\u2019s generally pretty clean and readable, but it is limited.<\/p>\n<h2>The Workaround That is the Topic of This Article<\/h2>\n<p>That brings us to the workaround that I came up with for this article. It involves <code>with<\/code> and context managers. If you\u2019ve followed my blog for a while, you may have read my articles earlier about <a href=\"https:\/\/programmingideaswithjake.wordpress.com\/2016\/01\/23\/kotlin-like-builders-in-java-and-python-continued-additional-parameters\/\">in Java and Python<\/a><a href=\"https:\/\/programmingideaswithjake.wordpress.com\/2016\/01\/16\/mimicking-kotlin-builders-in-java-and-python\/\">, in which I showed my initial findings for using context managers to do multiline lambdas. At the time, I placed limitations on them that aren\u2019t technically true. Before I get into that, though, I\u2019ll reshow how they can be used for lambdas.<br \/>\n<\/a><\/p>\n<p><a href=\"https:\/\/programmingideaswithjake.wordpress.com\/2016\/01\/16\/mimicking-kotlin-builders-in-java-and-python\/\">For a lambda that has no parameters and no return type, a <code>with<\/code> block is really simple:<\/a><\/p>\n<pre class=\"brush:php\">with someFunc():\r\n    # do something<\/pre>\n<p>For this case, it\u2019s just a simple context manager where <code>__enter__()<\/code> doesn\u2019t return anything.<br \/>\nFor a lambda that has one parameter and no return type, a <code>with<\/code> block is still pretty simple:<\/p>\n<pre class=\"brush:php\">with someFunc() as arg:\r\n    # use arg<\/pre>\n<p>To make this, you do a typical context manager, but <code>__enter__()<\/code> returns a value that is used for <code>arg<\/code>.\u00a0In the older articles, I presented these as the only ways that <code>with<\/code> blocks could be used for lambdas. Luckily, this actually covers a large majority of use cases, but it\u2019s actually not the extent of how far <code>with<\/code> block lambdas can go.<\/p>\n<h2>More Parameters<\/h2>\n<p>Say that we want to provide more parameters than 0 or 1. How do we get more? Well, directly, we can\u2019t, but because of iterable unpacking, we can do essentially the same thing! So, to get two parameters, <code>__enter__()<\/code> returns a tuple (or list \u2013 but a tuple is better) of two objects (i.e. <code>return thing1, thing2<\/code>).<br \/>\n<b>ASIDE:<\/b> A tuple is better than a list for a few reasons. First, there are no brackets required to make a tuple, so it looks cleaner. Second, a tuple is immutable, so it can\u2019t be accidentally messed with. If you want to design it so that an argument becomes an <code>out<\/code> argument, then you could use a list, but there are better, clearer ways to do this.<br \/>\nLet\u2019s make this a little more clear with an example:<\/p>\n<pre class=\"brush:php\">class MyContextManager:\r\n    def __enter__(self):\r\n        return 1, 2, 3, 4\r\n\r\n    def __exit__(self, type, exc, tb):\r\n        \u2026\r\n\r\nwith MyContextManager() as args:\r\n    one, two, three, four = args\r\n    print(one)\r\n    print(two)\r\n    print(three)\r\n    print(four)<\/pre>\n<p>This context manager is kind of worthless, since it simply gives back the values you gave it as a tuple to use in the <code>with<\/code> block, but it does demonstrate how multiple arguments can be provided to the \u201clambdas\u201d in the <code>with<\/code> blocks. I expect that the name <code>args<\/code> will generally be used unless a better name can be given for the specific situation. Also, you can see that it\u2019s easy to separate the arguments into something more useful in a single unpacking line.<\/p>\n<h2>Return Values<\/h2>\n<p>As I mentioned earlier in the aside about using tuples, you could technically pass in a list as the arguments use it to take care of the return value. This could be done by appending a return value to the end of the list or reassigning an item already in the list. This isn\u2019t all that terrible, mechanically, but it\u2019s confusing, error-prone, and doesn\u2019t read well.<br \/>\nSo, I\u2019ve got some alternatives, starting with my least favorite.<\/p>\n<h2>Return Parameter<\/h2>\n<p>With this technique, one of the arguments that is passed in (preferably the last) is a small mutable data store. It probably has a method along the lines of <code>_return(self, value)<\/code> that can be called within the <code>with<\/code> block. Calling it will set a value on the object which, if stored on the context manager, can be looked at in the <code>__exit__()<\/code> method.<\/p>\n<pre class=\"brush:php\">class OutParameter:\r\n    def _return(self, value):\r\n        self.return_value = value\r\n\r\nclass MyContextManager:\r\n    def __enter__(self):\r\n        self.return_value = OutParameter()\r\n        return 1, 2, 3, 4, self.return_value\r\n\r\n    def __exit__(self, type, exc, tb):\r\n        do_something_with(self.return_value.return_value)\r\n\r\nwith MyContextManager() as args:\r\n    one, two, three, four, out = args\r\n    \u2026\r\n    out._return(value)<\/pre>\n<p>This works, isn\u2019t too confusing, but seems to take up just a little excess space. Let\u2019s change it up just a little bit.<\/p>\n<h2>Function Signature<\/h2>\n<p>Instead of passing the object that will take on the return value as one of the arguments, you actually pass it as <i>all<\/i> the arguments. You see, it\u2019s possible to unpack <i>any<\/i> sequence object, and making one of those is super easy. I call this class <code>FunctionSignature<\/code>, since it encapsulates both the arguments as well as the return value, but I\u2019m not too keen on the name. I\u2019d happily accept some suggestions in the comments.<\/p>\n<pre class=\"brush:php\">from collections.abc import Sequence\r\nclass FunctionSignature(Sequence):\r\n    def arguments(self, *args):\r\n        self.args = args\r\n        return self\r\n\r\n    def _return(self, value):\r\n        self.return_value = value\r\n\r\n    def __getitem__(self, index):\r\n        return self.value[index]\r\n\r\n    def __len__(self):\r\n        return len(self.value)\r\n\r\nclass MyContextManager:\r\n    def __enter__(self):\r\n        self.sig = FunctionSignature()\r\n        return self.sig.arguments(1, 2, 3, 4)\r\n\r\n    def __exit__(self, type, exc, tb):\r\n        do_something_with(self.sig.return_value)\r\n\r\nwith MyContextManager() as args:\r\n    one, two, three, four = args\r\n    \u2026\r\n    args._return(value)<\/pre>\n<p>Now, if I were actually implementing <code>FunctionSignature<\/code>, I\u2019d override all of the <code>Sequence<\/code> methods (possibly without even inheriting from <code>Sequence<\/code>) to redirect to the internal tuple so that the less efficient mixin methods aren\u2019t used. But, for the sake of conciseness, I did the shortest, easiest way to create a sequence.<\/p>\n<p>Overall, this didn\u2019t save us much space. In fact, in total it was longer due to the larger definition of <code>FunctionSignature<\/code> versus <code>OutParameter<\/code>, but that length is a one-time thing versus the length of all the <code>with<\/code> blocks that use it. And we only saved a few characters on one line within the <code>with<\/code> block. Still, I like this idea more overall, since I feel like it puts a smaller mental burden on the user writing the <code>with<\/code> block. I could be wrong. What do you think?<\/p>\n<h2>Use the <code>contextmanager<\/code> Decorator<\/h2>\n<p>When making a context manager, I highly recommend using <a href=\"https:\/\/docs.python.org\/2\/library\/contextlib.html#contextlib.contextmanager\"><code>contextmanager<\/code> decorator<\/a> in the <code>contextlib<\/code> module. It makes writing the manager much easier, and it still works just fine with <code>OutParameter<\/code> and <code>FunctionSignature<\/code>.<\/p>\n<h2>Limitations<\/h2>\n<p>Now, despite the fact that I\u2019ve removed a few limitations from using <code>with] blocks for multi-line lambdas, there are still plenty of limitations, one of which was actually introduced by adding the ability to 'return' values.<\/code><\/p>\n<h2>Can Only Be Called Once<\/h2>\n<p>Normally, a function that uses a lambda is capable of using that lambda as many times as it wants. When it comes to a <code>with<\/code> block lambda, the block is only called once; between one call to <code>__enter__()<\/code> and one call to <code>__exit__()<\/code>.<\/p>\n<h2>There is No Function Object Involved<\/h2>\n<p>The block of code in a <code>with<\/code> block is not turned into a callable object that can be passed around. This means it can\u2019t be passed further into more specific functions and such.<\/p>\n<h2>Harder to Reuse Existing Functions<\/h2>\n<p><code>with<\/code> blocks don\u2019t accept functions and lambdas. So you can\u2019t just pass an already-defined function in to be used. To use a function, with arguments and return values, it would look like this:<\/p>\n<pre class=\"brush:php\">with cm as args:\r\n    args._return(some_func(*args))<\/pre>\n<p>That\u2019s way more than just <code>cm(some_func)<\/code>. Now, you <i>could<\/i> define the function in such a way that, if it does receive a function or lambda, it doesn\u2019t go into \u201ccontext manager mode\u201d.<\/p>\n<h2>The Highlander Problem<\/h2>\n<p>There can be only one. Only one \u201clambda\u201d can be passed in using a <code>with<\/code> block. I\u2019m pretty sure there\u2019s no way around this. If there is a way, I\u2019m certain that it\u2019s nearly impossible to read.<br \/>\nObviously, actual lambdas can be passed in, but that doesn\u2019t help the situation a ton.<\/p>\n<h2>Returns That Don\u2019t Return<\/h2>\n<p>When you call the <code>_return()<\/code> method, it doesn\u2019t exit out of the block. You\u2019ll have to use other control flow techniques to make sure that\u2019s the last thing called. Also, please don\u2019t try and be clever by purposely having code run after the return; that will just confuse readers more.<\/p>\n<h2><code>with<\/code> Statements Aren\u2019t Expressions<\/h2>\n<p>Normal functions that take lambdas are able to return something that can be used later. <code>with<\/code> statements don\u2019t return anything that can be used outside of themselves. This hurts functional programming, since it makes the code obviously impure.<\/p>\n<h2>Outro<\/h2>\n<p>So that\u2019s the craziness that is multi-line lambdas using <code>with<\/code> blocks. Remember the disclaimer at the top when it comes to making comments. I\u2019m particularly proud of this one, even if it\u2019s usually a bad idea. Thinking around languages like this is something I particularly enjoy doing, and I hope there are others out there that do, too.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"https:\/\/programmingideaswithjake.wordpress.com\/2016\/10\/01\/multi-line-lambdas-in-python\/\">Multi-Line Lambdas in Python<\/a> from our <a href=\"http:\/\/www.webcodegeeks.com\/join-us\/wcg\/\">WCG partner<\/a> Jacob Zimmerman at the <a href=\"http:\/\/programmingideaswithjake.wordpress.com\/\">Programming Ideas With Jake<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I need to preface all of this with a disclaimer:\u00a0I love Python, but I am able to see plenty of faults with it. In this article, I attempt to provide a very roundabout way of working around one of those faults: the lack of multi-line lambdas. This is not to say that this is a &hellip;<\/p>\n","protected":false},"author":51,"featured_media":1651,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[],"class_list":["post-14825","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Multi-Line Lambdas in Python - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"I need to preface all of this with a disclaimer:\u00a0I love Python, but I am able to see plenty of faults with it. In this article, I attempt to provide a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Multi-Line Lambdas in Python - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"I need to preface all of this with a disclaimer:\u00a0I love Python, but I am able to see plenty of faults with it. In this article, I attempt to provide a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-10-03T09:41:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jacob Zimmerman\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/jacobz_20\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jacob Zimmerman\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/\"},\"author\":{\"name\":\"Jacob Zimmerman\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f54a53cfb8523f4ef6012aa63f075c39\"},\"headline\":\"Multi-Line Lambdas in Python\",\"datePublished\":\"2016-10-03T09:41:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/\"},\"wordCount\":1613,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/\",\"name\":\"Multi-Line Lambdas in Python - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"datePublished\":\"2016-10-03T09:41:11+00:00\",\"description\":\"I need to preface all of this with a disclaimer:\u00a0I love Python, but I am able to see plenty of faults with it. In this article, I attempt to provide a\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Multi-Line Lambdas in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f54a53cfb8523f4ef6012aa63f075c39\",\"name\":\"Jacob Zimmerman\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2dfdd9e2d35ed2224faf73968f8c597b5489fc345287e06e2571d3935a6bcc86?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2dfdd9e2d35ed2224faf73968f8c597b5489fc345287e06e2571d3935a6bcc86?s=96&d=mm&r=g\",\"caption\":\"Jacob Zimmerman\"},\"description\":\"Jacob is a certified Java programmer (level 1) and Python enthusiast. He loves to solve large problems with programming and considers himself pretty good at design.\",\"sameAs\":[\"https:\/\/programmingideaswithjake.wordpress.com\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/jacobz_20\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/jacob-zimmerman\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Multi-Line Lambdas in Python - Web Code Geeks - 2026","description":"I need to preface all of this with a disclaimer:\u00a0I love Python, but I am able to see plenty of faults with it. In this article, I attempt to provide a","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/","og_locale":"en_US","og_type":"article","og_title":"Multi-Line Lambdas in Python - Web Code Geeks - 2026","og_description":"I need to preface all of this with a disclaimer:\u00a0I love Python, but I am able to see plenty of faults with it. In this article, I attempt to provide a","og_url":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2016-10-03T09:41:11+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","type":"image\/jpeg"}],"author":"Jacob Zimmerman","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/jacobz_20","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Jacob Zimmerman","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/"},"author":{"name":"Jacob Zimmerman","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f54a53cfb8523f4ef6012aa63f075c39"},"headline":"Multi-Line Lambdas in Python","datePublished":"2016-10-03T09:41:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/"},"wordCount":1613,"commentCount":1,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/","url":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/","name":"Multi-Line Lambdas in Python - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","datePublished":"2016-10-03T09:41:11+00:00","description":"I need to preface all of this with a disclaimer:\u00a0I love Python, but I am able to see plenty of faults with it. In this article, I attempt to provide a","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/python\/multi-line-lambdas-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/www.webcodegeeks.com\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Multi-Line Lambdas in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f54a53cfb8523f4ef6012aa63f075c39","name":"Jacob Zimmerman","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2dfdd9e2d35ed2224faf73968f8c597b5489fc345287e06e2571d3935a6bcc86?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2dfdd9e2d35ed2224faf73968f8c597b5489fc345287e06e2571d3935a6bcc86?s=96&d=mm&r=g","caption":"Jacob Zimmerman"},"description":"Jacob is a certified Java programmer (level 1) and Python enthusiast. He loves to solve large problems with programming and considers himself pretty good at design.","sameAs":["https:\/\/programmingideaswithjake.wordpress.com\/","https:\/\/x.com\/https:\/\/twitter.com\/jacobz_20"],"url":"https:\/\/www.webcodegeeks.com\/author\/jacob-zimmerman\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/14825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/51"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=14825"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/14825\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/1651"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=14825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=14825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=14825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}