{"id":896,"date":"2023-07-28T09:39:35","date_gmt":"2023-07-28T09:39:35","guid":{"rendered":"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/"},"modified":"2023-07-28T09:39:35","modified_gmt":"2023-07-28T09:39:35","slug":"zip-twee-lijsten-python","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/","title":{"rendered":"Hoe twee lijsten in python te comprimeren"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Vaak ben je misschien ge\u00efnteresseerd in het comprimeren (of &#8222;samenvoegen&#8220;) van twee lijsten in Python. Gelukkig is dit eenvoudig te doen met de functie zip().<\/span><\/p>\n<p> <span style=\"color: #000000;\">Deze tutorial toont verschillende voorbeelden van praktisch gebruik van deze functie.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 1: Comprimeer twee lijsten van gelijke lengte tot \u00e9\u00e9n lijst<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De volgende syntaxis laat zien hoe u twee lijsten van gelijke lengte tot \u00e9\u00e9n kunt comprimeren:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define list a and list b<\/span>\na = ['a', 'b', 'c']<\/strong>\n<strong>b = [1, 2, 3]\n\n<span style=\"color: #008080;\">#zip the two lists together into one list<\/span><\/strong>\n<strong>list( <span style=\"color: #3366ff;\">zip<\/span> (a,b))\n\n[('a', 1), ('b', 2), ('c', 3)]\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 2: Comprimeer twee lijsten van gelijke lengte in een woordenboek<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">De volgende syntaxis laat zien hoe u twee lijsten van gelijke lengte in een woordenboek comprimeert:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define list of keys and list of values<\/span>\n<\/strong><strong>keys = ['a', 'b', 'c']\nvalues = [1, 2, 3]\n\n<span style=\"color: #008080;\">#zip the two lists together into one dictionary<\/span><\/strong>\n<strong>dict( <span style=\"color: #3366ff;\">zip<\/span> (keys, values)) \n\n{'a': 1, 'b': 2, 'c': 3}\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Voorbeeld 3: Comprimeer twee lijsten van ongelijke lengte<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Als uw twee lijsten een ongelijke lengte hebben, wordt zip() afgekapt tot de lengte van de kortere lijst:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define list a and list b<\/span>\na = ['a', 'b', 'c', 'd']<\/strong>\n<strong>b = [1, 2, 3]\n\n<span style=\"color: #008080;\">#zip the two lists together into one list<\/span><\/strong>\n<strong>list( <span style=\"color: #3366ff;\">zip<\/span> (a,b))\n\n[('a', 1), ('b', 2), ('c', 3)]<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Als u wilt voorkomen dat zip() wordt ingekort tot de lengte van de kortste lijst, kunt u in plaats daarvan de functie <a href=\"https:\/\/docs.python.org\/3\/library\/itertools.html#itertools.zip_longest\" target=\"_blank\" rel=\"noopener\">zip_longest()<\/a> uit de <strong>itertools-<\/strong> bibliotheek gebruiken.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Standaard vult deze functie &#8218;Geen&#8216; in voor ontbrekende waarden:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">from<\/span> itertools <span style=\"color: #008000;\">import<\/span> zip_longest<\/span>\n\n#define list a and list b<\/span>\na = ['a', 'b', 'c', 'd']<\/strong>\n<strong>b = [1, 2, 3]\n\n<span style=\"color: #008080;\">#zip the two lists together without truncating to length of shortest list<\/span><\/strong>\n<strong>list( <span style=\"color: #3366ff;\">zip_longest<\/span> (a, b))\n\n[('a', 1), ('b', 2), ('c', 3), ('d', None)]\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">U kunt echter het <strong>opvulwaarde-<\/strong> argument gebruiken om een andere opvulwaarde op te geven:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define list a and list b<\/span>\na = ['a', 'b', 'c', 'd']<\/strong>\n<strong>b = [1, 2, 3]\n\n<span style=\"color: #008080;\">#zip the two lists together, using fill value of '0'<\/span><\/strong>\n<strong>list( <span style=\"color: #3366ff;\">zip_longest<\/span> (a, b, fillvalue= <span style=\"color: #339966;\">0<\/span> ))\n\n[('a', 1), ('b', 2), ('c', 3), ('d', 0)]\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><em>U kunt de volledige documentatie voor de functie zip_longest() <a href=\"https:\/\/docs.python.org\/3\/library\/itertools.html#itertools.zip_longest\" target=\"_blank\" rel=\"noopener\">hier<\/a> vinden.<\/em><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vaak ben je misschien ge\u00efnteresseerd in het comprimeren (of &#8222;samenvoegen&#8220;) van twee lijsten in Python. Gelukkig is dit eenvoudig te doen met de functie zip(). Deze tutorial toont verschillende voorbeelden van praktisch gebruik van deze functie. Voorbeeld 1: Comprimeer twee lijsten van gelijke lengte tot \u00e9\u00e9n lijst De volgende syntaxis laat zien hoe u twee [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-896","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Hoe twee lijsten in Python te comprimeren - Statorials<\/title>\n<meta name=\"description\" content=\"Een eenvoudige uitleg over hoe je twee lijsten samen kunt comprimeren in Python, inclusief verschillende voorbeelden.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hoe twee lijsten in Python te comprimeren - Statorials\" \/>\n<meta property=\"og:description\" content=\"Een eenvoudige uitleg over hoe je twee lijsten samen kunt comprimeren in Python, inclusief verschillende voorbeelden.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T09:39:35+00:00\" \/>\n<meta name=\"author\" content=\"Dr.benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr.benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"2\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/\",\"url\":\"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/\",\"name\":\"Hoe twee lijsten in Python te comprimeren - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-28T09:39:35+00:00\",\"dateModified\":\"2023-07-28T09:39:35+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"Een eenvoudige uitleg over hoe je twee lijsten samen kunt comprimeren in Python, inclusief verschillende voorbeelden.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe twee lijsten in python te comprimeren\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hoe twee lijsten in Python te comprimeren - Statorials","description":"Een eenvoudige uitleg over hoe je twee lijsten samen kunt comprimeren in Python, inclusief verschillende voorbeelden.","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:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/","og_locale":"de_DE","og_type":"article","og_title":"Hoe twee lijsten in Python te comprimeren - Statorials","og_description":"Een eenvoudige uitleg over hoe je twee lijsten samen kunt comprimeren in Python, inclusief verschillende voorbeelden.","og_url":"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/","og_site_name":"Statorials","article_published_time":"2023-07-28T09:39:35+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"2\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/","url":"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/","name":"Hoe twee lijsten in Python te comprimeren - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-28T09:39:35+00:00","dateModified":"2023-07-28T09:39:35+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"Een eenvoudige uitleg over hoe je twee lijsten samen kunt comprimeren in Python, inclusief verschillende voorbeelden.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/zip-twee-lijsten-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe twee lijsten in python te comprimeren"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=896"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/896\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}