{"id":20634,"date":"2020-08-01T01:24:16","date_gmt":"2020-08-01T08:24:16","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=20634"},"modified":"2023-12-01T03:57:15","modified_gmt":"2023-12-01T11:57:15","slug":"python-indexerror-list-assignment-index-out-of-range","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/","title":{"rendered":"Python indexerror: list assignment index out of range Solution"},"content":{"rendered":"\n<p>An IndexError is nothing to worry about. It\u2019s an error that is raised when you try to access an index that is outside of the size of a list. How do you solve this issue? Where can it be raised?<br><\/p>\n\n\n\n<p>In this article, we\u2019re going to answer those questions. We will discuss what IndexErrors are and how you can solve the \u201clist assignment index out of range\u201d error. We\u2019ll walk through an example to help you see exactly what causes this error.<br><\/p>\n\n\n\n<p>Without further ado, let\u2019s begin!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Problem: indexerror: list assignment index out of range<\/h2>\n\n\n\n<p>When you receive an error message, the first thing you should do is read it. An error message can tell you a lot about the nature of an error.<br><\/p>\n\n\n\n<p>Our error message is: <code>indexerror: list assignment index out of range.<\/code><br><\/p>\n\n\n\n<p>IndexError tells us that there is a problem with how we are accessing an <a href=\"https:\/\/careerkarma.com\/blog\/python-index\/\">index<\/a>. An index is a value inside an iterable object, such as a <a href=\"https:\/\/careerkarma.com\/blog\/python-list-methods\/\">list<\/a> or a string.<br><\/p>\n\n\n\n<p>The message \u201clist assignment index out of range\u201d tells us that we are trying to assign an item to an index that does not exist.<br><\/p>\n\n\n\n<p>In order to use indexing on a list, you need to initialize the list. If you try to assign an item into a list at an index position that does not exist, this error will be raised.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">An Example Scenario<\/h2>\n\n\n\n<p>The list assignment error is commonly raised in <a href=\"https:\/\/careerkarma.com\/blog\/python-for-loop\/\">for<\/a> and <a href=\"https:\/\/careerkarma.com\/blog\/do-while-python\/\">while loops<\/a>.<br><\/p>\n\n\n\n<p>We\u2019re going to write a program that adds all the cakes containing the word \u201cStrawberry\u201d into a new array. Let\u2019s start by declaring two variables:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>cakes = [&quot;Strawberry Tart&quot;, &quot;Chocolate Muffin&quot;, &quot;Strawberry Cheesecake&quot;]\nstrawberry = []<\/pre><\/div>\n\n\n\n<p>The first <a href=\"https:\/\/careerkarma.com\/blog\/python-variables\/\">variable<\/a> stores our list of cakes. The second variable is an empty list that will store all of the strawberry cakes. Next, we\u2019re going to write a loop that checks if each value in \u201ccakes\u201d contains the word \u201cStrawberry\u201d.<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>for c in range(0, len(cakes)):\n\tif &quot;Strawberry&quot; in cakes[c]:\n\t\tstrawberry[c] = cakes[c]\n\nprint(strawberry)<\/pre><\/div>\n\n\n\n<p>If a value contains \u201cStrawberry\u201d, it should be added to our new array. Otherwise, nothing will happen. Once our for loop has executed, the \u201cstrawberry\u201d array should be printed to the console. Let\u2019s run our code and see what happens:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Traceback (most recent call last):\n  File &quot;main.py&quot;, line 6, in &lt;module&gt;\n\tstrawberry[c] = cakes[c]\nIndexError: list assignment index out of range<\/pre><\/div>\n\n\n\n<p>As we expected, an error has been raised. Now we get to solve it!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Solution<\/h2>\n\n\n\n<p>Our error message tells us the line of code at which our program fails:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>strawberry[c] = cakes[c]<\/pre><\/div>\n\n\n\n<p>The problem with this code is that we are trying to assign a value inside our \u201cstrawberry\u201d list to a position that does not exist.<br><\/p>\n\n\n\n<p>When we create our strawberry array, it has no values. This means that it has no index numbers. The following values do not exist:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>strawberry[0]\nstrawberry[1]\n\u2026<\/pre><\/div>\n\n\n\n<p>We are trying to assign values to these positions in our for loop. Because these positions contain no values, an error is returned.<br><\/p>\n\n\n\n<p>We can solve this problem in two ways.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Solution with append()<\/h3>\n\n\n\n<p>First, we can add an item to the \u201cstrawberry\u201d array using <a href=\"https:\/\/careerkarma.com\/blog\/python-append-to-list\/\">append()<\/a>:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>cakes = [&quot;Strawberry Tart&quot;, &quot;Chocolate Muffin&quot;, &quot;Strawberry Cheesecake&quot;]\nstrawberry = []\n\nfor c in range(0, len(cakes)):\n\tif &quot;Strawberry&quot; in cakes[c]:\n\t\tstrawberry.append(cakes[c])\n\nprint(strawberry)<\/pre><\/div>\n\n\n\n<p>The <code>append()<\/code> method adds an item to an array and creates an index position for that item. Let\u2019s run our code: [\u2018Strawberry Tart\u2019, \u2018Strawberry Cheesecake\u2019].<br><\/p>\n\n\n\n<p>Our code works!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Solution with Initializing an Array<\/h3>\n\n\n\n<p>Alternatively, we can <a href=\"https:\/\/careerkarma.com\/blog\/how-to-initialize-a-list-in-python\/\">initialize our array with some values<\/a> when we declare it. This will create the index positions at which we can store values inside our \u201cstrawberry\u201d array.<br><\/p>\n\n\n\n<p>To initialize an array, you can use this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>strawberry = [] * 10<\/pre><\/div>\n\n\n\n<p>This will create an array with 10 empty values. Our code now looks like this:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>cakes = [&quot;Strawberry Tart&quot;, &quot;Chocolate Muffin&quot;, &quot;Strawberry Cheesecake&quot;]\nstrawberry = [] * 10\n\nfor c in range(0, len(cakes)):\n\tif &quot;Strawberry&quot; in cakes[c]:\n\t\tstrawberry.append(cakes[c])\n\nprint(strawberry)<\/pre><\/div>\n\n\n\n<p>Let\u2019s try to run our code: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>['Strawberry Tart', 'Strawberry Cheesecake']<\/pre><\/div>\n\n\n\n<p>Our code successfully returns an array with all the strawberry cakes.<br><\/p>\n\n\n\n<p>This method is best to use when you know exactly how many values you&#8217;re going to store in an array.<br><\/p>\n\n\n\n<p>Our above code is somewhat inefficient because we have initialized \u201cstrawberry\u201d with 10 empty values. There are only a total of three cakes in our \u201ccakes\u201d array that could possibly contain \u201cStrawberry\u201d. In most cases, using the append() method is both more elegant and more efficient.<\/p>\n\n\n\n<iframe loading=\"lazy\" frameborder=\"0\" width=\"100%\" height=\"400px\" src=\"https:\/\/repl.it\/@careerkarma\/list-assignment-index-out-of-range?lite=true\"><\/iframe>\n<br>\n<br>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>IndexErrors are raised when you try to use an item at an index value that does not exist. The \u201cindexerror: list assignment index out of range\u201d is raised when you try to assign an item to an index position that does not exist.<br><\/p>\n\n\n\n<p>To solve this error, you can use <code>append()<\/code> to add an item to a list. You can also initialize a list before you start inserting values to avoid this error.<br><\/p>\n\n\n\n<p>Now you\u2019re ready to start solving the list assignment error like a professional Python developer!<\/p>\n","protected":false},"excerpt":{"rendered":"An IndexError is nothing to worry about. It\u2019s an error that is raised when you try to access an index that is outside of the size of a list. How do you solve this issue? Where can it be raised? In this article, we\u2019re going to answer those questions. We will discuss what IndexErrors are&hellip;","protected":false},"author":240,"featured_media":17975,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-20634","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":[]},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python indexerror: list assignment index out of range | Career Karma<\/title>\n<meta name=\"description\" content=\"On Career Karma, learn about the Python indexerror: list assignment index out of range error, how the error works, and how to solve the error.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python indexerror: list assignment index out of range Solution\" \/>\n<meta property=\"og:description\" content=\"On Career Karma, learn about the Python indexerror: list assignment index out of range error, how the error works, and how to solve the error.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-01T08:24:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:57:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/christin-hume-mfB1B1s4sMc-unsplash-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python indexerror: list assignment index out of range Solution\",\"datePublished\":\"2020-08-01T08:24:16+00:00\",\"dateModified\":\"2023-12-01T11:57:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/\"},\"wordCount\":743,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/christin-hume-mfB1B1s4sMc-unsplash-1.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/\",\"name\":\"Python indexerror: list assignment index out of range | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/christin-hume-mfB1B1s4sMc-unsplash-1.jpg\",\"datePublished\":\"2020-08-01T08:24:16+00:00\",\"dateModified\":\"2023-12-01T11:57:15+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"On Career Karma, learn about the Python indexerror: list assignment index out of range error, how the error works, and how to solve the error.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/christin-hume-mfB1B1s4sMc-unsplash-1.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/christin-hume-mfB1B1s4sMc-unsplash-1.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-indexerror-list-assignment-index-out-of-range\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python indexerror: list assignment index out of range Solution\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python indexerror: list assignment index out of range | Career Karma","description":"On Career Karma, learn about the Python indexerror: list assignment index out of range error, how the error works, and how to solve the error.","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:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/","og_locale":"en_US","og_type":"article","og_title":"Python indexerror: list assignment index out of range Solution","og_description":"On Career Karma, learn about the Python indexerror: list assignment index out of range error, how the error works, and how to solve the error.","og_url":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-08-01T08:24:16+00:00","article_modified_time":"2023-12-01T11:57:15+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/christin-hume-mfB1B1s4sMc-unsplash-1.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python indexerror: list assignment index out of range Solution","datePublished":"2020-08-01T08:24:16+00:00","dateModified":"2023-12-01T11:57:15+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/"},"wordCount":743,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/christin-hume-mfB1B1s4sMc-unsplash-1.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/","url":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/","name":"Python indexerror: list assignment index out of range | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/christin-hume-mfB1B1s4sMc-unsplash-1.jpg","datePublished":"2020-08-01T08:24:16+00:00","dateModified":"2023-12-01T11:57:15+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"On Career Karma, learn about the Python indexerror: list assignment index out of range error, how the error works, and how to solve the error.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/christin-hume-mfB1B1s4sMc-unsplash-1.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/christin-hume-mfB1B1s4sMc-unsplash-1.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-assignment-index-out-of-range\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python indexerror: list assignment index out of range Solution"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/20634","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=20634"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/20634\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/17975"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=20634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=20634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=20634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}