{"id":208960,"date":"2019-12-31T14:54:07","date_gmt":"2019-12-31T14:54:07","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=208960"},"modified":"2019-12-31T14:56:59","modified_gmt":"2019-12-31T14:56:59","slug":"advanced-python-features-lambda-map-filter","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/","title":{"rendered":"Advanced Python Features(Lambda, Map, Filter)"},"content":{"rendered":"\n<p>Python is a simple, easy to use yet powerful language.  Python includes an infinite number of built-in functions. Here we will discuss some of the beautiful things of the python.<br><br><strong>Lambda<\/strong>: Lambda is an anonymous function. Anonymous functions in python mean that these functions don&#8217;t have a name and we write them as one-liners. Normal functions in python start with a def keyword and have a function name.  In other words, anonymous does not start with def and does not have any function name. Lambda is one such type of function. Lambda function has one expression and can take any type of argument.<br><br><em>Syntax:<br>lambda arguments: expression<\/em><br><br><strong>Example:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre class=\"EnlighterJSRAW\">#Normal Python function\ndef add(a, b):\n  return a+ b\nx = add(2,3)\nprint(x)\nOutput = 5\n#Lambda Function\nx = lambda a, b : a +b\nprint(x(5,6))\n#Output = 11\n\nx = lambda a, b, c : a + b + c\nprint(x(5,2,3))\n#Output = 10<\/pre>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<p><strong>Map<\/strong>: Map is a Python built-in function that is used to iterate an iterable through a specified function. It executes the function through each item in the iterable. It is used to apply a function to a sequence of elements like a list or dictionary.<br><br><em>Syntax:<br>map(fun, iterable)<\/em><br><strong>Example<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre class=\"EnlighterJSRAW\">def sum(a,b):\n  return a+b\nx = map(sum,[1,2,3],[1,2,3])\nprint(x) \n#Output = [2,4,6]\n\ndef length(a):\n  return len(a)\nx  = map(length, (&quot;apple&quot;,&quot;orange&quot;,&quot;banana&quot;))\nprint(x) \n#Output = [5,6,6]<\/pre>\n<\/div><\/div>\n\n\n\n<p><br><strong>Filter<\/strong>: Filter is similar to the map but it only returns those values for which the applied function returns True.  The&nbsp;function returns an iterator where the items are filtered through a function to test if the item is accepted or not.<br><br><em>Syntax:<br>filter(function,&nbsp;iterable)<\/em><br><br><strong>Example<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\nnum = [5,8,9,11,15,13,21,119,120]\ndef filter_fun(x):\n  if x &lt; 100:\n    return False\n  else:\n    return True\nx = filter(filter_fun, num)\nfor a in x:\n  print(a)\n#Output :\n119\n120<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Python is a simple, easy to use yet powerful language. Python includes an infinite number of built-in functions. Here we will discuss some of the beautiful things of the python. Lambda: Lambda is an anonymous function. Anonymous functions in python mean that these functions don&#8217;t have a name and we write them as one-liners. Normal <a href=\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":88,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[879,375],"class_list":["post-208960","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-filter","tag-map"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>python advanced features map, filter, lambda<\/title>\n<meta name=\"description\" content=\"Python advanced features map filter and lambda\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"python advanced features map, filter, lambda\" \/>\n<meta property=\"og:description\" content=\"Python advanced features map filter and lambda\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-31T14:54:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-31T14:56:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Jahangir Naik\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jahangir Naik\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/\"},\"author\":{\"name\":\"Jahangir Naik\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/d3efd6f1d02c2713752e7cba0b626ca6\"},\"headline\":\"Advanced Python Features(Lambda, Map, Filter)\",\"datePublished\":\"2019-12-31T14:54:07+00:00\",\"dateModified\":\"2019-12-31T14:56:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/\"},\"wordCount\":213,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"filter\",\"map\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/\",\"url\":\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/\",\"name\":\"python advanced features map, filter, lambda\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2019-12-31T14:54:07+00:00\",\"dateModified\":\"2019-12-31T14:56:59+00:00\",\"description\":\"Python advanced features map filter and lambda\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Advanced Python Features(Lambda, Map, Filter)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/d3efd6f1d02c2713752e7cba0b626ca6\",\"name\":\"Jahangir Naik\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/20021fdcdb324166dd5aef0f183ffb391facf8853dd58f9fcabc0950f4118c01?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/20021fdcdb324166dd5aef0f183ffb391facf8853dd58f9fcabc0950f4118c01?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Jahangir Naik\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/jahangir260\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"python advanced features map, filter, lambda","description":"Python advanced features map filter and lambda","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:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/","og_locale":"en_US","og_type":"article","og_title":"python advanced features map, filter, lambda","og_description":"Python advanced features map filter and lambda","og_url":"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2019-12-31T14:54:07+00:00","article_modified_time":"2019-12-31T14:56:59+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Jahangir Naik","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Jahangir Naik","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/"},"author":{"name":"Jahangir Naik","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/d3efd6f1d02c2713752e7cba0b626ca6"},"headline":"Advanced Python Features(Lambda, Map, Filter)","datePublished":"2019-12-31T14:54:07+00:00","dateModified":"2019-12-31T14:56:59+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/"},"wordCount":213,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["filter","map"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/","url":"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/","name":"python advanced features map, filter, lambda","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2019-12-31T14:54:07+00:00","dateModified":"2019-12-31T14:56:59+00:00","description":"Python advanced features map filter and lambda","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/advanced-python-features-lambda-map-filter\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Advanced Python Features(Lambda, Map, Filter)"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/d3efd6f1d02c2713752e7cba0b626ca6","name":"Jahangir Naik","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/20021fdcdb324166dd5aef0f183ffb391facf8853dd58f9fcabc0950f4118c01?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/20021fdcdb324166dd5aef0f183ffb391facf8853dd58f9fcabc0950f4118c01?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Jahangir Naik"},"url":"https:\/\/webkul.com\/blog\/author\/jahangir260\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/208960","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/88"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=208960"}],"version-history":[{"count":39,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/208960\/revisions"}],"predecessor-version":[{"id":218622,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/208960\/revisions\/218622"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=208960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=208960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=208960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}