{"id":2293,"date":"2019-12-21T15:17:59","date_gmt":"2019-12-21T09:47:59","guid":{"rendered":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/?p=2293"},"modified":"2023-12-30T15:41:42","modified_gmt":"2023-12-30T10:11:42","slug":"python-map-function","status":"publish","type":"post","link":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/","title":{"rendered":"Python map Function Explanation and Examples"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_65 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#What_is_Python_map_function\" title=\"What is Python map() function?\">What is Python map() function?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#Syntax_of_Python_map_function\" title=\"Syntax of Python map function\">Syntax of Python map function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#Parameters_of_Python_map_function\" title=\"Parameters of Python map function \">Parameters of Python map function <\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#First_argument_A_function\" title=\" First argument: A function \"> First argument: A function <\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#Second_argument_An_iterable\" title=\" Second argument: An iterable \"> Second argument: An iterable <\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#Examples_Python_map_with_string\" title=\"Examples:  Python map() with string \">Examples:  Python map() with string <\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#Python_map_with_tuple\" title=\"Python map() with tuple\">Python map() with tuple<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#Python_map_with_list\" title=\"Python map() with list\">Python map() with list<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#Example_Python_map_function_with_lambda_function\" title=\"Example: Python map() function with lambda function\">Example: Python map() function with lambda function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#Example_Passing_multiple_arguments_to_map_function_in_Python\" title=\"Example: Passing multiple arguments to map() function in Python \">Example: Passing multiple arguments to map() function in Python <\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#Conclusion\" title=\"Conclusion\">Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#Trending_Python_Articles\" title=\"Trending Python Articles\">Trending Python Articles<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-what-is-python-map-function\"><span class=\"ez-toc-section\" id=\"What_is_Python_map_function\"><\/span>What is Python map() function?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p> The purpose of the Python map function is to apply the same procedure to every item in an iterable data structure. Iterable data structures can include lists, generators, strings, etc. In a very basic example, the map can iterate over every item in a list and apply a function to each item.<\/p>\n\n\n\n<p> Python borrows the concept of&nbsp;<strong>the map&nbsp;<\/strong>from the functional programming domain. It is an inbuilt function that is used to apply the function on all the elements of specified iterable and return map objects.  the <strong>map<\/strong>&nbsp;can also be used in situations like calling a particular method on all objects stored in a list which change the state of the object. <\/p>\n\n\n\n<p>Also Read: <a href=\"https:\/\/www.pythonpool.com\/fibonacci-series-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Fibonacci series in Python (opens in a new tab)\">Fibonacci series in Python<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-syntax-of-python-map-function\"><span class=\"ez-toc-section\" id=\"Syntax_of_Python_map_function\"><\/span>Syntax of Python map function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Python map() function syntax is:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nmap(function, iterable, ...)\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-parameters-of-python-map-function\"><span class=\"ez-toc-section\" id=\"Parameters_of_Python_map_function\"><\/span><strong>Parameters<\/strong> of Python map function <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>function :<\/strong><em>&nbsp;It is a function to which map passes each element of given iterable.<\/em>\n<strong>iterable :<\/strong><em>&nbsp;It is a iterable which is to be mapped.<\/em> <\/pre>\n\n\n\n<p class=\"has-text-color has-background has-link-color wp-elements-b6c9b73dd33e841ba63b1a4f36ca2fe6\" style=\"color:#ffffff;background-color:#611313\"> <strong>NOTE:<\/strong>\u00a0You can pass one or more iterable to the map() function. <\/p>\n\n\n\n<p>We can pass multiple iterable arguments to map() function, in that case, the specified function must have that many arguments. The function will be applied to these iterable elements in parallel. With multiple iterable arguments, the map iterator stops when the shortest iterable is exhausted.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-first-argument-a-function\"><span class=\"ez-toc-section\" id=\"First_argument_A_function\"><\/span> First argument: A function <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The map function accepts a function as the first argument. When we think about a function in Python, we automatically think about the <strong><code>def<\/code><\/strong> keyword, but the map function does not only accept <strong>functions created by the user<\/strong> using&nbsp;<code>def<\/code>&nbsp;keyword but also built-in and anonymous functions, and even methods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-second-argument-an-iterable\"><span class=\"ez-toc-section\" id=\"Second_argument_An_iterable\"><\/span> Second argument: An iterable <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When we think about an iterable We automatically think about lists, but iterables are much more than <strong>lists<\/strong>. An iterable is an object with a countable number of values that can be iterated for example using a <strong>for loop, Sets, tuples, dictionaries<\/strong> are <strong>iterables<\/strong> as well, and they can be used as the second argument of the map function.\u00a0 <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-examples-python-map-with-string\"><span class=\"ez-toc-section\" id=\"Examples_Python_map_with_string\"><\/span>Examples:  Python map() with string <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndef to_upper_case(s):\n    return str(s).upper()\n<\/pre><\/div>\n\n\n<p>It\u2019s a simple function that returns the upper case string representation of the input object.<\/p>\n\n\n\n<p>I am also defining a utility function to print iterator elements. The function will print iterator elements with white space and will be reused in all the code snippets.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndef print_iterator(it):\n    for x in it:\n        print(x, end=' ')\n    print('')  # for new line\n<\/pre><\/div>\n\n\n<p>Let\u2019s look at the map() function example with different types of iterables.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# map() with string\nmap_iterator = map(to_upper_case, 'abc')\nprint(type(map_iterator))\nprint_iterator(map_iterator)\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&lt;class 'map'&gt;\nA B C \n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-map-with-tuple\"><span class=\"ez-toc-section\" id=\"Python_map_with_tuple\"><\/span>Python map() with tuple<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# map() with tuple\nmap_iterator = map(to_upper_case, (1, 'a', 'abc'))\nprint_iterator(map_iterator)\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n1 A ABC \n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-map-with-list\"><span class=\"ez-toc-section\" id=\"Python_map_with_list\"><\/span>Python map() with list<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nmap_iterator = map(to_upper_case, &#x5B;'x', 'a', 'abc'])\nprint_iterator(map_iterator)\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nX A ABC\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-python-map-function-with-lambda-function\"><span class=\"ez-toc-section\" id=\"Example_Python_map_function_with_lambda_function\"><\/span>Example: Python map() function with lambda function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the map() function along with iterable sequence, we can also the lambda function. Let\u2019s use a lambda function to reverse each string in the list as we did above using a global function, Python<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlistOfStr = &#x5B;'hi', 'this' , 'is', 'a', 'very', 'simple', 'string' , 'for', 'us']\n \n# Reverse each string in the list using lambda function &amp; map()\nmodifiedList = list(map(lambda x : x&#x5B;::-1], listOfStr))\n \nprint('Modified List : ', modifiedList)\n<\/pre><\/div>\n\n\n<p style=\"font-size:18px\">Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nModified List :  &#x5B;'ih', 'siht', 'si', 'a', 'yrev', 'elpmis', 'gnirts', 'rof', 'su']\n<\/pre><\/div>\n\n\n<p>It iterates over the list of string and applies lambda function on each string element. Then stores the value returned by lambda function to a new sequence for each element. Then in last returns the new sequence of reversed string elements.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-passing-multiple-arguments-to-map-function-in-python\"><span class=\"ez-toc-section\" id=\"Example_Passing_multiple_arguments_to_map_function_in_Python\"><\/span>Example: Passing multiple arguments to map() function in Python <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The map() function, along with a function as an argument can also pass multiple sequences like lists as arguments. Let\u2019s see how to pass 2 lists in<br>map() function and get a joined list based on them.<\/p>\n\n\n\n<p class=\"has-normal-font-size\">Suppose we have two lists i.e.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist1 = &#x5B;'hi', 'this', 'is', 'a', 'very', 'simple', 'string', 'for', 'us']\nlist2 = &#x5B;11,22,33,44,55,66,77,88,99]\n<\/pre><\/div>\n\n\n<p>Now we want to join elements from list1 to list2 and create a new list of the same size from these joined lists i.e. new lists should be like this, <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&#x5B;'hi_11', 'this_22', 'is_33', 'a_44', 'very_55', 'simple_66', 'string_77', 'for_88', 'us_99']\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol>\n<li>The map function has two arguments (1) a function, and (2) an iterable.<\/li>\n\n\n\n<li>Applies the function to each element of the iterable and returns a map object.<\/li>\n\n\n\n<li> The returned map object can be easily converted in another iterable using built-in functions. <\/li>\n<\/ol>\n\n\n\n<p>Read More about <a aria-label=\"Python Maps (opens in a new tab)\" href=\"https:\/\/docs.python.org\/3\/library\/functions.html#map\" target=\"_blank\" rel=\"noreferrer noopener\">Python Maps<\/a><\/p>\n\n\n\n<p>If you didn&#8217;t find what you were looking, then do suggest us in the comments below. We will be more than happy to add that. <\/p>\n\n\n<div class=\"monsterinsights-widget-popular-posts monsterinsights-widget-popular-posts-delta monsterinsights-popular-posts-styled monsterinsights-widget-popular-posts-columns-2\"><h2 class=\"monsterinsights-widget-popular-posts-widget-title\"><span class=\"ez-toc-section\" id=\"Trending_Python_Articles\"><\/span>Trending Python Articles<span class=\"ez-toc-section-end\"><\/span><\/h2><ul class=\"monsterinsights-widget-popular-posts-list\"><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_.webp 1200w \" alt=\"[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 11, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined.webp 1200w \" alt=\"[Fixed] nameerror: name Unicode is not defined\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] nameerror: name Unicode is not defined<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal.webp 1200w \" alt=\"[Solved] runtimeerror: cuda error: invalid device ordinal\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Solved] runtimeerror: cuda error: invalid device ordinal<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-type-numpy-ndarray-doesnt-define-__round__-method\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method.webp 1200w \" alt=\"[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><\/ul><\/div><p><\/p>","protected":false},"excerpt":{"rendered":"<p>What is Python map() function? The purpose of the Python map function is to apply the same procedure to every item in an iterable data &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Python map Function Explanation and Examples\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-map-function\/#more-2293\" aria-label=\"More on Python map Function Explanation and Examples\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2301,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4,15],"tags":[33,30,27,31,34,35,32,24,36,25,28,37,38,29,26],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v22.4) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python map Function Explanation and Examples - Python Pool<\/title>\n<meta name=\"description\" content=\"Python map() function takes two arguments: an iterable and a function, and apply it to each element of the iterable (list, tuple, etc.) Syntax of the map()\" \/>\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.pythonpool.com\/python-map-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python map Function Explanation and Examples\" \/>\n<meta property=\"og:description\" content=\"What is Python map() function? The purpose of the Python map function is to apply the same procedure to every item in an iterable data structure. Iterable\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-map-function\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-21T09:47:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-30T10:11:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2019\/12\/Capture-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1018\" \/>\n\t<meta property=\"og:image:height\" content=\"613\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Python Pool\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Python Pool\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-map-function\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-map-function\/\"},\"author\":{\"name\":\"Python Pool\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998\"},\"headline\":\"Python map Function Explanation and Examples\",\"datePublished\":\"2019-12-21T09:47:59+00:00\",\"dateModified\":\"2023-12-30T10:11:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-map-function\/\"},\"wordCount\":635,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-map-function\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2019\/12\/Capture-1.jpg\",\"keywords\":[\"how to use map function in python\",\"how to use map in python\",\"map function\",\"map function python\",\"map in python\",\"map() python\",\"python list\",\"python map\",\"python map example\",\"python map function\",\"python map function examples\",\"python map lambda\",\"python map list\",\"what does map do in python\",\"what is map function in python\"],\"articleSection\":[\"Programs\",\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-map-function\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/python-map-function\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-map-function\/\",\"name\":\"Python map Function Explanation and Examples - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-map-function\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-map-function\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2019\/12\/Capture-1.jpg\",\"datePublished\":\"2019-12-21T09:47:59+00:00\",\"dateModified\":\"2023-12-30T10:11:42+00:00\",\"description\":\"Python map() function takes two arguments: an iterable and a function, and apply it to each element of the iterable (list, tuple, etc.) Syntax of the map()\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-map-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-map-function\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-map-function\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2019\/12\/Capture-1.jpg\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2019\/12\/Capture-1.jpg\",\"width\":1018,\"height\":613,\"caption\":\"Python map Function\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-map-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python map Function Explanation and Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/twitter.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998\",\"name\":\"Python Pool\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b170f9f39a7cad6ab2d2b1c4bc7b79f5?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b170f9f39a7cad6ab2d2b1c4bc7b79f5?s=96&d=wavatar&r=g\",\"caption\":\"Python Pool\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python map Function Explanation and Examples - Python Pool","description":"Python map() function takes two arguments: an iterable and a function, and apply it to each element of the iterable (list, tuple, etc.) Syntax of the map()","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:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/","og_locale":"en_US","og_type":"article","og_title":"Python map Function Explanation and Examples","og_description":"What is Python map() function? The purpose of the Python map function is to apply the same procedure to every item in an iterable data structure. Iterable","og_url":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/","og_site_name":"Python Pool","article_published_time":"2019-12-21T09:47:59+00:00","article_modified_time":"2023-12-30T10:11:42+00:00","og_image":[{"width":1018,"height":613,"url":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2019\/12\/Capture-1.jpg","type":"image\/jpeg"}],"author":"Python Pool","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Python Pool","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/#article","isPartOf":{"@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/"},"author":{"name":"Python Pool","@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998"},"headline":"Python map Function Explanation and Examples","datePublished":"2019-12-21T09:47:59+00:00","dateModified":"2023-12-30T10:11:42+00:00","mainEntityOfPage":{"@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/"},"wordCount":635,"commentCount":0,"publisher":{"@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/#primaryimage"},"thumbnailUrl":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2019\/12\/Capture-1.jpg","keywords":["how to use map function in python","how to use map in python","map function","map function python","map in python","map() python","python list","python map","python map example","python map function","python map function examples","python map lambda","python map list","what does map do in python","what is map function in python"],"articleSection":["Programs","Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/","url":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/","name":"Python map Function Explanation and Examples - Python Pool","isPartOf":{"@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/#primaryimage"},"image":{"@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/#primaryimage"},"thumbnailUrl":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2019\/12\/Capture-1.jpg","datePublished":"2019-12-21T09:47:59+00:00","dateModified":"2023-12-30T10:11:42+00:00","description":"Python map() function takes two arguments: an iterable and a function, and apply it to each element of the iterable (list, tuple, etc.) Syntax of the map()","breadcrumb":{"@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/#primaryimage","url":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2019\/12\/Capture-1.jpg","contentUrl":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2019\/12\/Capture-1.jpg","width":1018,"height":613,"caption":"Python map Function"},{"@type":"BreadcrumbList","@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/python-map-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Python map Function Explanation and Examples"}]},{"@type":"WebSite","@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/#website","url":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/twitter.com\/pythonpool","https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998","name":"Python Pool","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/secure.gravatar.com\/avatar\/b170f9f39a7cad6ab2d2b1c4bc7b79f5?s=96&d=wavatar&r=g","contentUrl":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/secure.gravatar.com\/avatar\/b170f9f39a7cad6ab2d2b1c4bc7b79f5?s=96&d=wavatar&r=g","caption":"Python Pool"}}]}},"_links":{"self":[{"href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/2293"}],"collection":[{"href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=2293"}],"version-history":[{"count":10,"href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/2293\/revisions"}],"predecessor-version":[{"id":31316,"href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/2293\/revisions\/31316"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/2301"}],"wp:attachment":[{"href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=2293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=2293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=2293"}],"curies":[{"name":"wp","href":"https:\/\/web.archive.org\/web\/20240926032326\/https:\/\/api.w.org\/{rel}","templated":true}]}}