{"id":10653,"date":"2016-02-10T16:15:19","date_gmt":"2016-02-10T14:15:19","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=10653"},"modified":"2018-01-09T09:46:20","modified_gmt":"2018-01-09T07:46:20","slug":"python-map-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/","title":{"rendered":"Python Map Example"},"content":{"rendered":"<p>In this tutorial, by using python 3.4, we&#8217;ll talk about map functions.<\/p>\n<p>Strictly speaking, a <code>map<\/code> function, is a function that accepts a function and an array as arguments, and applies the given function to each element of the array, returning another array with the result of each transformation.<\/p>\n<p>So, in other words, a map applies a transformation to each element of an array and returns the results.<\/p>\n<p>How would we implement it? Let&#8217;s see a simple implementation to understand how a map works:<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;R7QVpFMZmjosABLC&#8217;]<\/p>\n<h2>1. Map Implementation<\/h2>\n<p><span style=\"text-decoration: underline\"><em>custom_map.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\ndef custom_map(transformation, array):\r\n    return [transformation(e) for e in array]\r\n<\/pre>\n<p>So, we defined a function that receives a transformation and an array as arguments, and using for comprehension it returns an array of the transformations of each of these elements. To use it:<\/p>\n<p><span style=\"text-decoration: underline\"><em>custom_map.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\ndef custom_map(transformation, array):\r\n    return [transformation(e) for e in array]\r\n\r\n\r\ndef add_one(x): return x + 1\r\n\r\n\r\ndef test():\r\n    my_array = [1, 2, 3, 4, 5]\r\n    print(str(custom_map(add_one, my_array)))\r\n\r\nif __name__ == \"__main__\":\r\n    test()\r\n\r\n<\/pre>\n<p>As functions are first class objects in python, we can define a function called <code>add_one<\/code> and pass it as argument to our <code>custom_map<\/code> with an array containing from 1 to 5. The output, as we expected, is:<\/p>\n<pre class=\"brush:bash\">\r\n[2, 3, 4, 5, 6]\r\n<\/pre>\n<h2>2. Python&#8217;s Map<\/h2>\n<p>Now, Python provides a built-in <code>map<\/code> function, which behaves almost like our custom map. The differences:<\/p>\n<ul>\n<li>It does not return a list, but a <code>map object<\/code>, but if you apply <code>list<\/code> to it, will become a list.<\/li>\n<li>It does not accept only one array, but <em>n<\/em> instead, passing <em>n<\/em> arguments to the provided transformation, applying it to the items of the provided arrays in parallel (returning None as default if an array is shorter than others) like: <code>transformation(array1[0], array2[0], ..., arrayN[0])<\/code>.<\/li>\n<\/ul>\n<p>So, let&#8217;s see an example of this:<\/p>\n<p><span style=\"text-decoration: underline\"><em>multiply.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\ndef multiply(x, y):\r\n    return x * y\r\n\r\n\r\ndef test():\r\n    xs = [1, 2, 3, 4, 5, 6, 7, 8]\r\n    ys = [2, 3, 4, 5, 6, 7]\r\n    map_object = map(multiply, xs, ys)\r\n    result_list = list(map_object)\r\n    print(str(result_list))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    test()\r\n\r\n<\/pre>\n<p>Here, we defined an array <code>xs<\/code> and another one <code>ys<\/code> and <code>ys<\/code> is shorter than <code>xs<\/code>. The result will look like:<\/p>\n<pre class=\"brush:bash\">\r\n[2, 6, 12, 20, 30, 42]\r\n<\/pre>\n<p>As you see, the result contains as many arguments as the shorter array, as there are not enough arguments to pass to our transformation function (<code>multiply<\/code>).<\/p>\n<p>Also, notice we apply the function <code>list<\/code> to the result, instead of printing it directly, as the result of a map function is not a list, but a <code>map object<\/code> as we said before.<\/p>\n<p>In real life, we often don&#8217;t want to define a function to pass it to a map, as it probably will only be used there. <em>Lambdas come to help<\/em>. Let&#8217;s refactor our multiply to see this:<\/p>\n<p><span style=\"text-decoration: underline\"><em>multiply.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\ndef test():\r\n    xs = [1, 2, 3, 4, 5, 6, 7, 8]\r\n    ys = [2, 3, 4, 5, 6, 7]\r\n    map_object = map(lambda x, y: x * y, xs, ys)\r\n    result_list = list(map_object)\r\n    print(str(result_list))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    test()\r\n\r\n<\/pre>\n<p>The output will look the same, and our function is now defined right there, one the run, so we don&#8217;t have to worry about someone reusing it if they are not meant to.<\/p>\n<p>Let&#8217;s see a real life case scenario in which map comes to save the day. Imagine a scenario in which you have a catalog of products and for each product a history of prices that looks like this:<\/p>\n<p><span style=\"text-decoration: underline\"><em>example.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nfrom datetime import datetime\r\n\r\nproducts = {\r\n    1: {\r\n        \"id\": 1,\r\n        \"name\": \"Python Book\"\r\n    },\r\n    2: {\r\n        \"id\": 2,\r\n        \"name\": \"JavaScript Book\"\r\n    },\r\n    3: {\r\n        \"id\": 3,\r\n        \"name\": \"HTML Book\"\r\n    }\r\n}\r\nprices = {\r\n    1: [\r\n        {\r\n            \"id\": 1,\r\n            \"product_id\": 1,\r\n            \"amount\": 2.75,\r\n            \"date\": datetime(2016, 2, 1, 11, 11, 17, 683987)\r\n        },\r\n        {\r\n            \"id\": 4,\r\n            \"product_id\": 1,\r\n            \"amount\": 3.99,\r\n            \"date\": datetime(2016, 2, 5, 11, 11, 17, 683987)\r\n        }\r\n    ],\r\n    2: [\r\n        {\r\n            \"id\": 2,\r\n            \"product_id\": 2,\r\n            \"amount\": 1.10,\r\n            \"date\": datetime(2015, 1, 5, 11, 11, 17, 683987)\r\n        },\r\n        {\r\n            \"id\": 2,\r\n            \"product_id\": 2,\r\n            \"amount\": 1.99,\r\n            \"date\": datetime(2015, 12, 5, 11, 11, 17, 683987)\r\n        }\r\n    ],\r\n    3: [\r\n        {\r\n            \"id\": 3,\r\n            \"product_id\": 3,\r\n            \"amount\": 3,\r\n            \"date\": datetime(2015, 12, 20, 11, 11, 17, 683987)\r\n        }\r\n    ]\r\n}\r\n<\/pre>\n<p>When you are going to show these products to the public, you want to attach to each of them the last updated price. So, given this issue, a function which does attach the last price to a product looks like this:<\/p>\n<p><span style=\"text-decoration: underline\"><em>example.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\n...\r\n\r\ndef complete_product(product):\r\n    if product is None:\r\n        return None\r\n    product_prices = prices.get(product.get(\"id\"))\r\n    if product_prices is None:\r\n        return None\r\n    else:\r\n        p = product.copy()\r\n        p[\"price\"] = max(product_prices, key=lambda price: price.get(\"date\")).copy()\r\n        return p\r\n<\/pre>\n<p>This function receives a product as argument, and if it&#8217;s not None and there are prices for this product, it returns a copy of the product with a copy of its last price attached. The functions that use this one looks like this:<\/p>\n<p><span style=\"text-decoration: underline\"><em>example.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\n...\r\ndef get_product(product_id):\r\n    return complete_product(products.get(product_id))\r\n\r\n\r\ndef many_products(ids):\r\n    return list(map(get_product, ids))\r\n\r\n\r\ndef all_products():\r\n    return list(map(complete_product, products.values()))\r\n<\/pre>\n<p>The first one, <code>get_product<\/code>, is pretty simple, it just reads one product and returns the result of applying <code>complete_product<\/code> to it. The other ones are the functions that are of interest to us.<\/p>\n<p>The second function assumes, without any validation, that <code>ids<\/code> is an iterable of integers. It applies a map to it passing the function <code>get_product<\/code> as transformation, and with the resulting map object, it creates a list.<\/p>\n<p>The third function receives no parameters, it just applies a map to every product, passing <code>complete_product<\/code> as transformation.<\/p>\n<p>Another example of a use case of <code>map<\/code> would be when we need to discard information. Imagine a service that provides all users in an authentication system. Of course, the passwords would be hashed, therefor, not readable, but still it would be a bad idea to return those hashed with the users. Let&#8217;s see:<\/p>\n<p><span style=\"text-decoration: underline\"><em>example2.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nusers = [\r\n    {\r\n        \"name\": \"svinci\",\r\n        \"salt\": \"098u n4v04\",\r\n        \"hashed_password\": \"q423uinf9304fh2u4nf3410uth1394hf\"\r\n    },\r\n    {\r\n        \"name\": \"admin\",\r\n        \"salt\": \"0198234nva\",\r\n        \"hashed_password\": \"3894tumn13498ujc843jmcv92384vmqv\"\r\n    }\r\n]\r\n\r\n\r\ndef all_users():\r\n    def discard_passwords(user):\r\n        u = user.copy()\r\n        del u[\"salt\"]\r\n        del u[\"hashed_password\"]\r\n        return u\r\n    return list(map(discard_passwords, users))\r\n\r\n\r\nprint(str(all_users()))\r\n<\/pre>\n<p>In <code>all_users<\/code> we are applying <code>discard_passwords<\/code> to all users an creating a list with the result. The transformation function receives a user, an returns a copy of it with the salt and hashed_passwords removed.<\/p>\n<h2>3. Map Object<\/h2>\n<p>Now, we&#8217;ve been transforming this map object to a list, which is not wrong at all, it&#8217;s the most common use case, but there is another way.<\/p>\n<p>A map object is an iterator that applies the transformation function to every item of the provided iterable, yielding the results. This is a neat solution, which optimizes a lot memory consumption, as the transformation is applied only when the element is requested.<\/p>\n<p>Also, as the map objects are iterators, we can use them directly. Let&#8217;s see the full example and refactor it a bit to use map objects instead of lists.<\/p>\n<p><span style=\"text-decoration: underline\"><em>example.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\ndef complete_product(product):\r\n    if product is None:\r\n        return None\r\n    product_prices = prices.get(product.get(\"id\"))\r\n    if product_prices is None:\r\n        return None\r\n    else:\r\n        p = product.copy()\r\n        p[\"price\"] = max(product_prices, key=lambda price: price.get(\"date\")).copy()\r\n        return p\r\n\r\n\r\ndef get_product(product_id):\r\n    return complete_product(products.get(product_id))\r\n\r\n\r\ndef many_products(ids):\r\n    return map(get_product, ids)\r\n\r\n\r\ndef all_products():\r\n    return map(complete_product, products.values())\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    print(\"printing all...\")\r\n    ps = all_products()\r\n    for p in ps:\r\n        print(str(p))\r\n    print(\"printing all, but by all ids...\")\r\n    ids = map(lambda p: p.get(\"id\"), all_products())\r\n    ps = many_products(ids)\r\n    for p in ps:\r\n        print(str(p))\r\n<\/pre>\n<p>The functions that changed are <code>many_products<\/code> and <code>all_products<\/code>, which now retrieve the map object instead of a list.<\/p>\n<p>We are retrieving all products, and iterating through the map object printing each product. Notice that map objects, as they are iterators, can be iterated only once, so, we are retrieving all once again to get the ids and then retrieving by its ids and printing all again. The output below.<\/p>\n<pre class=\"brush:bash\">\r\nprinting all...\r\n{'id': 1, 'name': 'Python Book', 'price': {'id': 4, 'product_id': 1, 'amount': 3.99, 'date': datetime.datetime(2016, 2, 5, 11, 11, 17, 683987)}}\r\n{'id': 2, 'name': 'JavaScript Book', 'price': {'id': 2, 'product_id': 2, 'amount': 1.99, 'date': datetime.datetime(2015, 12, 5, 11, 11, 17, 683987)}}\r\n{'id': 3, 'name': 'HTML Book', 'price': {'id': 3, 'product_id': 3, 'amount': 3, 'date': datetime.datetime(2015, 12, 20, 11, 11, 17, 683987)}}\r\nprinting all, but by all ids...\r\n{'id': 1, 'name': 'Python Book', 'price': {'id': 4, 'product_id': 1, 'amount': 3.99, 'date': datetime.datetime(2016, 2, 5, 11, 11, 17, 683987)}}\r\n{'id': 2, 'name': 'JavaScript Book', 'price': {'id': 2, 'product_id': 2, 'amount': 1.99, 'date': datetime.datetime(2015, 12, 5, 11, 11, 17, 683987)}}\r\n{'id': 3, 'name': 'HTML Book', 'price': {'id': 3, 'product_id': 3, 'amount': 3, 'date': datetime.datetime(2015, 12, 20, 11, 11, 17, 683987)}}\r\n<\/pre>\n<p>In the users example the code will look like this:<\/p>\n<pre class=\"brush:python\">\r\nusers = [\r\n    {\r\n        \"name\": \"svinci\",\r\n        \"salt\": \"098u n4v04\",\r\n        \"hashed_password\": \"q423uinf9304fh2u4nf3410uth1394hf\"\r\n    },\r\n    {\r\n        \"name\": \"admin\",\r\n        \"salt\": \"0198234nva\",\r\n        \"hashed_password\": \"3894tumn13498ujc843jmcv92384vmqv\"\r\n    }\r\n]\r\n\r\n\r\ndef all_users():\r\n    def discard_passwords(user):\r\n        u = user.copy()\r\n        del u[\"salt\"]\r\n        del u[\"hashed_password\"]\r\n        return u\r\n    return map(discard_passwords, users)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    us = all_users()\r\n    for u in us:\r\n        print(str(u))\r\n\r\n<\/pre>\n<p>Again, the <code>all_users<\/code> function didn&#8217;t change too much, it just returns the map object directly. The main code now iterates over the map printing each user one by one.<\/p>\n<h2>4. Download the Code Project<\/h2>\n<p>This was an basic example on Python&#8217;s <code>map<\/code> function.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/> You can download the full source code of this example here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/02\/map.zip\"><strong>python-map<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, by using python 3.4, we&#8217;ll talk about map functions. Strictly speaking, a map function, is a function that accepts a function and an array as arguments, and applies the given function to each element of the array, returning another array with the result of each transformation. So, in other words, a map &hellip;<\/p>\n","protected":false},"author":109,"featured_media":1651,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[314,324],"class_list":["post-10653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-functional-programming","tag-map"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Map Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In this tutorial, by using python 3.4, we&#039;ll talk about map functions. Strictly speaking, a map function, is a function that accepts a function and an\" \/>\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\/python-map-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Map Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, by using python 3.4, we&#039;ll talk about map functions. Strictly speaking, a map function, is a function that accepts a function and an\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/\" \/>\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:author\" content=\"https:\/\/www.facebook.com\/sgvinci\" \/>\n<meta property=\"article:published_time\" content=\"2016-02-10T14:15:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-09T07:46:20+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=\"Sebastian Vinci\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sebastianvinci_\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sebastian Vinci\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/\"},\"author\":{\"name\":\"Sebastian Vinci\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/06a43c63e373dff2e159bbc029b405aa\"},\"headline\":\"Python Map Example\",\"datePublished\":\"2016-02-10T14:15:19+00:00\",\"dateModified\":\"2018-01-09T07:46:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/\"},\"wordCount\":939,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"keywords\":[\"Functional Programming\",\"map\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/\",\"name\":\"Python Map Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"datePublished\":\"2016-02-10T14:15:19+00:00\",\"dateModified\":\"2018-01-09T07:46:20+00:00\",\"description\":\"In this tutorial, by using python 3.4, we'll talk about map functions. Strictly speaking, a map function, is a function that accepts a function and an\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#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\/python-map-example\/#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\":\"Python Map Example\"}]},{\"@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\/06a43c63e373dff2e159bbc029b405aa\",\"name\":\"Sebastian Vinci\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g\",\"caption\":\"Sebastian Vinci\"},\"description\":\"Sebastian is a full stack programmer, who has strong experience in Java and Scala enterprise web applications. He is currently studying Computers Science in UBA (University of Buenos Aires) and working a full time job at a .com company as a Semi-Senior developer, involving architectural design, implementation and monitoring. He also worked in automating processes (such as data base backups, building, deploying and monitoring applications).\",\"sameAs\":[\"http:\/\/www.webcodegeeks.com\/\",\"https:\/\/www.facebook.com\/sgvinci\",\"https:\/\/x.com\/sebastianvinci_\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/sebastian-vinci\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Map Example - Web Code Geeks - 2026","description":"In this tutorial, by using python 3.4, we'll talk about map functions. Strictly speaking, a map function, is a function that accepts a function and an","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\/python-map-example\/","og_locale":"en_US","og_type":"article","og_title":"Python Map Example - Web Code Geeks - 2026","og_description":"In this tutorial, by using python 3.4, we'll talk about map functions. Strictly speaking, a map function, is a function that accepts a function and an","og_url":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/sgvinci","article_published_time":"2016-02-10T14:15:19+00:00","article_modified_time":"2018-01-09T07:46:20+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":"Sebastian Vinci","twitter_card":"summary_large_image","twitter_creator":"@sebastianvinci_","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Sebastian Vinci","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/"},"author":{"name":"Sebastian Vinci","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/06a43c63e373dff2e159bbc029b405aa"},"headline":"Python Map Example","datePublished":"2016-02-10T14:15:19+00:00","dateModified":"2018-01-09T07:46:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/"},"wordCount":939,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","keywords":["Functional Programming","map"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/","url":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/","name":"Python Map Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","datePublished":"2016-02-10T14:15:19+00:00","dateModified":"2018-01-09T07:46:20+00:00","description":"In this tutorial, by using python 3.4, we'll talk about map functions. Strictly speaking, a map function, is a function that accepts a function and an","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/python\/python-map-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/python\/python-map-example\/#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\/python-map-example\/#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":"Python Map Example"}]},{"@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\/06a43c63e373dff2e159bbc029b405aa","name":"Sebastian Vinci","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g","caption":"Sebastian Vinci"},"description":"Sebastian is a full stack programmer, who has strong experience in Java and Scala enterprise web applications. He is currently studying Computers Science in UBA (University of Buenos Aires) and working a full time job at a .com company as a Semi-Senior developer, involving architectural design, implementation and monitoring. He also worked in automating processes (such as data base backups, building, deploying and monitoring applications).","sameAs":["http:\/\/www.webcodegeeks.com\/","https:\/\/www.facebook.com\/sgvinci","https:\/\/x.com\/sebastianvinci_"],"url":"https:\/\/www.webcodegeeks.com\/author\/sebastian-vinci\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/10653","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\/109"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=10653"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/10653\/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=10653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=10653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=10653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}