

{"id":123243,"date":"2023-11-02T16:45:17","date_gmt":"2023-11-02T11:15:17","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=123243"},"modified":"2024-02-28T11:42:13","modified_gmt":"2024-02-28T06:12:13","slug":"python-program-on-lambda-with-map-function","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/","title":{"rendered":"Python Program on Lambda with Map Function"},"content":{"rendered":"<p>In this article, we will explore a Python program that employs the map function in combination with a lambda function. The map function is a built-in Python function that applies a specified function to all items in an input list and returns an iterable (often a list) of the results. The program showcases the use of map and a lambda function to calculate the square of each element in a given list.<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li>Familiarity with the map function.<\/li>\n<li>Understanding of lambda functions.<\/li>\n<li>Knowledge of list operations in Python.<\/li>\n<\/ul>\n<h3>Topic Explanation<\/h3>\n<p>This program begins by creating a list called mylist containing numeric values. It proceeds to leverage the map function in conjunction with a lambda function to calculate the square of each element in mylist. These squared values are stored in a new list, mylist1, and subsequently displayed.<\/p>\n<p>Through this approach, the program effectively demonstrates how the map function, combined with lambda functions, simplifies mathematical operations on lists. Readers gain insight into utilizing these tools for efficient data transformations, enhancing their proficiency in Python programming.<\/p>\n<h4><strong>Program Code:<\/strong><\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Program for Map with Lambda\r\n# Define a list of integers\r\nmylist = [10, 3, 20, 6, 4, 30]\r\n\r\n# Use the map function with a lambda expression to square each element in the list\r\n# The lambda function takes an input x and returns x squared (x*x)\r\nmylist1 = list(map(lambda x: x*x, mylist))\r\n\r\n# Print the resulting list containing the squared values of the original elements\r\nprint(mylist1)<\/pre>\n<div class=\"df-code-out\"><strong>Output:<\/strong><br \/>\n[100, 9, 400, 36, 16, 900]<\/div>\n<h4>Code Explanation:<\/h4>\n<ul>\n<li>Creates a list called mylist with elements 2, 3, 5, 6, 4, 7<\/li>\n<li>Defines a lambda function x:(x*x) that takes one argument x and returns its square<\/li>\n<li>Passes the lambda function and mylist to map() function<\/li>\n<li>map() will apply the lambda function to each element in mylist and return a map object<\/li>\n<li>Converts the map object to list using list() and stores result in mylist1<\/li>\n<li>Lambda function squares each element in mylist<\/li>\n<li>So mylist1 contains squares of each element in mylist i.e [4, 9, 25, 36, 16, 49]<\/li>\n<li>Finally, prints the mylist1 containing squared values<\/li>\n<\/ul>\n<h3>Summary<\/h3>\n<p>In conclusion, this article demonstrated the use of the map function with a lambda expression in Python. The program showcased how to square each element in a list efficiently. Readers, familiar with basic Python concepts like map and lambda functions, can easily understand and implement this approach. The provided code and its explanation serve as a straightforward example for those looking to enhance their Python skills, highlighting the practical application of these fundamental functions in real-world scenarios.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will explore a Python program that employs the map function in combination with a lambda function. The map function is a built-in Python function that applies a specified function to&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[28660,28663,10333,28664,28626,28662],"class_list":["post-123243","post","type-post","status-publish","format-standard","hentry","category-python","tag-lambda-function","tag-lambda-with-map-function-in-python","tag-python","tag-python-lambda-with-map-function","tag-python-practical","tag-python-program-on-lambda-with-map-function"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Program on Lambda with Map Function - DataFlair<\/title>\n<meta name=\"description\" content=\"Python program that employs the map function in combination with a lambda function. The program showcased how to square each element in a list efficiently.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Program on Lambda with Map Function - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python program that employs the map function in combination with a lambda function. The program showcased how to square each element in a list efficiently.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-02T11:15:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-28T06:12:13+00:00\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Program on Lambda with Map Function - DataFlair","description":"Python program that employs the map function in combination with a lambda function. The program showcased how to square each element in a list efficiently.","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:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/","og_locale":"en_US","og_type":"article","og_title":"Python Program on Lambda with Map Function - DataFlair","og_description":"Python program that employs the map function in combination with a lambda function. The program showcased how to square each element in a list efficiently.","og_url":"https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-11-02T11:15:17+00:00","article_modified_time":"2024-02-28T06:12:13+00:00","author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Python Program on Lambda with Map Function","datePublished":"2023-11-02T11:15:17+00:00","dateModified":"2024-02-28T06:12:13+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/"},"wordCount":350,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"keywords":["lambda function","lambda with map function in python","Python","python lambda with map function","python practical","python program on lambda with map function"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/","url":"https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/","name":"Python Program on Lambda with Map Function - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"datePublished":"2023-11-02T11:15:17+00:00","dateModified":"2024-02-28T06:12:13+00:00","description":"Python program that employs the map function in combination with a lambda function. The program showcased how to square each element in a list efficiently.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-lambda-with-map-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Program on Lambda with Map Function"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/123243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=123243"}],"version-history":[{"count":3,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/123243\/revisions"}],"predecessor-version":[{"id":134131,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/123243\/revisions\/134131"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=123243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=123243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=123243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}