{"id":4930,"date":"2024-10-08T07:21:26","date_gmt":"2024-10-08T07:21:26","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=4930"},"modified":"2024-10-08T07:21:28","modified_gmt":"2024-10-08T07:21:28","slug":"how-to-split-list-into-even-chunks-in-python","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/","title":{"rendered":"How to Split List Into Even Chunks in Python"},"content":{"rendered":"\n<p>Lists are popular data structures used by almost every Python developer. Sometimes, you may need to split a list into evenly sized chunks or N size chunks in Python. There are several ways to easily do it. In this article, we will learn how to split Python list into N sized chunks.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of 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: #999;color:#999\" 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: #999;color:#999\" 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 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#Split_Python_List_into_N_Size_Chunks\" >Split Python List into N Size Chunks<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#1_Using_Yield_Keyword\" >1. Using Yield Keyword<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#2_Using_List_Comprehension\" >2. Using List Comprehension<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#3_Using_itertools\" >3. Using itertools<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#4_Using_Numpy\" >4. Using Numpy<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#5_Using_Loop\" >5. Using Loop<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Split_Python_List_into_N_Size_Chunks\"><\/span>Split Python List into N Size Chunks<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We will look at 5 different ways to split list into N size chunks in Python. Let us say you have the following Python lists.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<br>lst1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<\/pre>\n\n\n\n<p>Let us say you want to split these lists into evenly sized chunks of 2 items each. Let us look at the different ways to do this.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_Yield_Keyword\"><\/span>1. Using Yield Keyword<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Yield keyword is an important feature in Python programming language. It returns a generator iterator object instead of returning all the actual values. This iterator is like a pointer to the generator function. Every time the iterator is accessed, it returns the next value of the sequence using the generator function, instead of returning the entire sequence at once. Since it does not store or return all the values, except the iterator, it is very memory efficient and fast. Here is how to use yield keyword to split our list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def split_list(l,n):<br>    for i in range(0, len(l),n):<br>        yield l[i:i+n]<br><br>lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<br>chunk_size=2<br>chunks=list(split_list(lst,chunk_size))<br>print(chunks)<br><br># Output<br>[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]<\/pre>\n\n\n\n<p>If your list has some elements that are left after splitting the original list, they are put into a separate list.  Let us say your list has 11 items and you want to split them into smaller lists of 2 items each, then here is the output you will get.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">lst1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br>split_list(lst1,n)<br><br># Output<br>[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], <strong>[11]<\/strong>]<\/pre>\n\n\n\n<p>Using yield keyword is really useful when you have large lists which can take up large amount of memory. In all use cases, it is one of the fastest and memory efficient ways to split lists.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_List_Comprehension\"><\/span>2. Using List Comprehension<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Understanding <a href=\"https:\/\/ubiq.co\/tech-blog\/what-does-yield-keyword-do-in-python\/\">what yield keyword does<\/a> can be difficult. In this case, you can use list comprehensions to split your list. List comprehensions are mainly created to provide a simple, easy way to create a list from another iterable object such as lists, tuples, etc.<\/p>\n\n\n\n<p>Here is a simple example to illustrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chunk_size=2<br>chunks = [lst[i:i + chunk_size] for i in range(0, len(lst), chunk_size)]<br>print(chunks)<\/pre>\n\n\n\n<p>Here is the output you will get.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]<\/pre>\n\n\n\n<p>Let us look at the expression used for list comprehension in detail. The range function creates a list of indexes, one for each list item, based on original list items. The for loop basically loops through this list of by skipping 2 (chunk_size) items at a time. So the value of i in above expression is 0, 2, 4, &#8230; <\/p>\n\n\n\n<p>In each iteration, we slice and return a chunk of original list such that the first item is the loop index i of for loop, and the number of items in the chunk is equal to chunk size. The chunks returned are [1, 2], [3, 4]&#8230;<\/p>\n\n\n\n<p>If your original list contains leftover items, they will be put in a separate list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">lst1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br>chunk_size=2<br>chunks = [lst[i:i + chunk_size] for i in range(0, len(lst), chunk_size)]<br>print(chunks)<br><br># Output<br>[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]<strong>, [11]<\/strong>]<\/pre>\n\n\n\n<p>You can also add the above code to create a function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def split_list(l, n):\n    chunks = [l[i:i + n] for i in range(0, len(l), n)]\n    print(chunks) \n\nsplit_list(lst,2)<\/pre>\n\n\n\n<p>Using list comprehensions is a very compact and elegant way to split lists. They were specifically created for this purpose.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_itertools\"><\/span>3. Using itertools<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The above 2 methods do not use any library. In this method, we will use itertools library, which provides many useful functions to work with iterables such as lists. It provides islice() function for this purpose. It is already present in every Python installation so you do not need to install it separately.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from itertools import islice<br>lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br>def split_list(l, chunk_size):<br>     l = iter(l)<br>     return iter(lambda: tuple(islice(l, chunk_size)), ())<br><br>list(split_list(lst,2))<br>[(1, 2), (3, 4), (5, 6), (7, 8), (9, 10), (11,)]<\/pre>\n\n\n\n<p>In the above code, we first import islice() function. We then define split_list() function that generates an iterable to the input list, using iter() function. Then we use islice() function to split the original list into smaller tuples of 2 items each. We return an iterator to this tuple. Lastly, we call split_list() function inside a list to store all resultant tuples in a list.<\/p>\n\n\n\n<p>Of course, if you want only a list of lists and not list of tuples, you can always loop through the iterable and convert each tuple into list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in chunk(lst,2):<br>     print(list(i))<br><br>[1, 2]<br>[3, 4]<br>[5, 6]<br>[7, 8]<br>[9, 10]<br>[11]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_Numpy\"><\/span>4. Using Numpy<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/numpy.org\/install\/\" target=\"_blank\" rel=\"noreferrer noopener\">Numpy<\/a> is another library that provides tons of useful functions for data analysis. In fact, it has a dedicated function array_split() that allows you to split a list into chunks. It just requires two arguments &#8211; the list to be split, and chunk size.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import numpy as np<br><br>lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br>chunk_size=2<br>np.array_split(lst, chunk_size)<\/pre>\n\n\n\n<p>Please note, numpy is not present in default Python installation and needs to be installed separately using the following command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ pip install numpy<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_Loop\"><\/span>5. Using Loop<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Lastly, we have the good old fashioned simple loop, where we iterate through the original list, and create the smaller lists of N size, by adding items to them one by one. This is perhaps the simplest solution of them all.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]<br>chunk_size=2<br>for i in range(0, len(lst),chunk_size):<br>    print(lst[i:i+chunk_size])<br><br># Output<br>[1, 2]<br>[3, 4]<br>[5, 6]<br>[7, 8]<br>[9, 10]<br>[11]<\/pre>\n\n\n\n<p>If you want, you can create a function using the above code. This will make it easy to reuse the above code.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def split_list(l, n):<br>    for i in range(0, len(l), n):<br>        print(lst[i:i+n])<br><br>split_list(lst, chunk_size)<\/pre>\n\n\n\n<p>Instead of printing each of the chunks, if you want to store them in a separate list, you can modify the function as shown below. Here we simply store the chunks in another list and return it at the end of for loop.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def split_list(l, n):<br>    new_lst=[]<br>    for i in range(0, len(l), n):<br>        new_lst.append(lst[i:i+n])<br>    return new_lst<br><br>x=split_list(lst, chunk_size)<br>print(x)<\/pre>\n\n\n\n<p>This method is useful for small-medium sized lists but not large lists since it loads the entire list as well as the chunks in memory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several different ways to split a list into N sized chunks. They all give the same result. Some solutions are more memory efficient than others while some are faster than the others. If you are working with large lists and have space constraints, then use yield keyword, since it is fast and does not require much memory to run. On the other hand, if you find it complicated, then use list comprehensions. If you are free to use libraries in your code, then you can try using itertools or numpy, both of which are really fast and efficient. If you are just looking for a very simple code to split a small-medium list into chunks, then you can use for loop as shown in the last solution, or use array_split() function offered by numpy library.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-backup-mysql-database-in-python\/\">How to Backup MySQL Database in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/what-does-if-__name__-__main__-do\/\">What Does Name-Main Idiom Do in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/what-are-metaclasses-in-python\/\">What Are Metaclasses in Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python developers need to split list into N size chunks. Here are different ways to split Python into even chunks.<\/p>\n","protected":false},"author":1,"featured_media":4958,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[316],"class_list":["post-4930","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-split-list"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Split List Into Even Chunks in Python - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Python developers need to split list into N size chunks. Here are different ways to split Python into even chunks.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Split List Into Even Chunks in Python - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Python developers need to split list into N size chunks. Here are different ways to split Python into even chunks.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-08T07:21:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-08T07:21:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/split-list-in-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"308\" \/>\n\t<meta property=\"og:image:height\" content=\"204\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Split List Into Even Chunks in Python\",\"datePublished\":\"2024-10-08T07:21:26+00:00\",\"dateModified\":\"2024-10-08T07:21:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/\"},\"wordCount\":1013,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/split-list-in-python.jpg?fit=308%2C204&ssl=1\",\"keywords\":[\"split list\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/\",\"name\":\"How to Split List Into Even Chunks in Python - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/split-list-in-python.jpg?fit=308%2C204&ssl=1\",\"datePublished\":\"2024-10-08T07:21:26+00:00\",\"dateModified\":\"2024-10-08T07:21:28+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Python developers need to split list into N size chunks. Here are different ways to split Python into even chunks.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/split-list-in-python.jpg?fit=308%2C204&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/split-list-in-python.jpg?fit=308%2C204&ssl=1\",\"width\":308,\"height\":204,\"caption\":\"split list in python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-split-list-into-even-chunks-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Split List Into Even Chunks in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Split List Into Even Chunks in Python - Ubiq BI","description":"Python developers need to split list into N size chunks. Here are different ways to split Python into even chunks.","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:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Split List Into Even Chunks in Python - Ubiq BI","og_description":"Python developers need to split list into N size chunks. Here are different ways to split Python into even chunks.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2024-10-08T07:21:26+00:00","article_modified_time":"2024-10-08T07:21:28+00:00","og_image":[{"width":308,"height":204,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/split-list-in-python.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Split List Into Even Chunks in Python","datePublished":"2024-10-08T07:21:26+00:00","dateModified":"2024-10-08T07:21:28+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/"},"wordCount":1013,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/split-list-in-python.jpg?fit=308%2C204&ssl=1","keywords":["split list"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/","name":"How to Split List Into Even Chunks in Python - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/split-list-in-python.jpg?fit=308%2C204&ssl=1","datePublished":"2024-10-08T07:21:26+00:00","dateModified":"2024-10-08T07:21:28+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Python developers need to split list into N size chunks. Here are different ways to split Python into even chunks.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/split-list-in-python.jpg?fit=308%2C204&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/split-list-in-python.jpg?fit=308%2C204&ssl=1","width":308,"height":204,"caption":"split list in python"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Split List Into Even Chunks in Python"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/10\/split-list-in-python.jpg?fit=308%2C204&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1hw","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/4930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=4930"}],"version-history":[{"count":33,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/4930\/revisions"}],"predecessor-version":[{"id":4964,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/4930\/revisions\/4964"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/4958"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=4930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=4930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=4930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}