{"id":20630,"date":"2020-08-01T00:44:00","date_gmt":"2020-08-01T07:44:00","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=20630"},"modified":"2023-12-01T03:57:14","modified_gmt":"2023-12-01T11:57:14","slug":"python-indexerror-list-index-out-of-range","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/","title":{"rendered":"Python indexerror: list index out of range Solution"},"content":{"rendered":"\n<p>IndexErrors are one of the most common types of runtime errors in Python. They\u2019re raised when you try to access an index value inside a <a href=\"https:\/\/careerkarma.com\/blog\/python-list-methods\/\">Python list<\/a> that does not exist. In most cases, index errors are easy to resolve. You just need to do a little bit of debugging.<br><\/p>\n\n\n\n<p>In this tutorial, we\u2019re going to talk about the \u201cindexerror: list index out of range\u201d error. We\u2019ll discuss how it works and walk through an example scenario where this error is present so that we can solve it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Problem: indexerror: list index out of range<\/h2>\n\n\n\n<p>As always, the best place to start is to read and break down our error message:&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>indexerror: list index out of range<\/pre><\/div>\n\n\n\n<p>This error message tells us that we\u2019re trying to access a value inside an array that does not have an index position.<br><\/p>\n\n\n\n<p>In Python, <a href=\"https:\/\/careerkarma.com\/blog\/python-index\/\">index numbers start from 0<\/a>. Here&#8217;s a typical Python array:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>programming_languages = [&quot;Java&quot;, &quot;Python&quot;, &quot;C++&quot;]<\/pre><\/div>\n\n\n\n<p>This array contains three values. The first list element, Java, has the index value 0. Each subsequent value has an index number 1 greater than the last. For instance, Python\u2019s index value is 1.<br><\/p>\n\n\n\n<p>If we try to access an item at the index position 3, an error will be returned. The last item in our array has the index value 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example Scenarios (and Solutions)<\/h2>\n\n\n\n<p>There are two common scenarios in which the &#8220;list index out of range&#8221; error is raised:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>When you try to iterate through a list and forget that lists are indexed from zero.<\/li><li>When you forget to use <a href=\"https:\/\/careerkarma.com\/blog\/python-range\/\">range()<\/a> to iterate over a list.<\/li><\/ul>\n\n\n\n<p>Let&#8217;s walk through both of these scenarios.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Lists Are Indexed From Zero<\/h3>\n\n\n\n<p>The following program prints out all the values in a list called \u201cprogramming_languages\u201d to the Python shell:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>programming_languages = [&quot;Java&quot;, &quot;Python&quot;, &quot;C++&quot;]\ncount = 0 \n\nwhile count &lt;= len(programming_languages):\n\tprint(programming_languages[count])\n\tcount += 1<\/pre><\/div>\n\n\n\n<p>First, we have declared two variables. The variable \u201cprogramming_languages\u201d stores the list of languages that we want to print to the console. The variable \u201ccount\u201d is used to track how many values we have printed out to the console.<br><\/p>\n\n\n\n<p>Next, we have declared a <a href=\"https:\/\/careerkarma.com\/blog\/do-while-python\/\">while loop<\/a>. This loop prints out the value from the \u201cprogramming_languages\u201d at the index position stored in \u201ccount\u201d. Then, it adds 1 to the \u201ccount\u201d variable. This loop continues until the value of \u201ccount\u201d is no longer less than or equal to the length of the \u201cprogramming_languages\u201d list.<br><\/p>\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>Java\nPython\nC++\nTraceback (most recent call last):\n  File &quot;main.py&quot;, line 5, in &lt;module&gt;\n\tprint(programming_languages[count])\nIndexError: list index out of range<\/pre><\/div>\n\n\n\n<p>All the values in our list are printed to the console but an error is raised. The problem is that our loop keeps going until the value of \u201ccount\u201d is no longer less than or equal to the length of \u201cprogramming_languages\u201d. This means that its last iteration will check for:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>programming_languages[3]<\/pre><\/div>\n\n\n\n<p>This value does not exist. This causes an IndexError. To solve this problem, we can change our operator from &lt;= to &lt;. This will ensure that our list only iterates until the value of \u201ccount\u201d is no longer less than the length of \u201cprogramming_languages\u201d. Let\u2019s make this revision:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>programming_languages = [&quot;Java&quot;, &quot;Python&quot;, &quot;C++&quot;]\ncount = 0 \n\nwhile count &lt; len(programming_languages):\n\tprint(programming_languages[count])\n\tcount += 1<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Java\nPython\nC++<\/pre><\/div>\n\n\n\n<p>We\u2019ve successfully solved the error! Our loop is no longer trying to print out programming_languages[3]. It stops when the value of \u201ccount\u201d is equal to 3 because 3 is not less than the length of \u201cprogramming_languages\u201d.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Forget to Use range()<\/h3>\n\n\n\n<p>When you\u2019re iterating over a list of numbers, it&#8217;s easy to forget to include a <a href=\"https:\/\/careerkarma.com\/blog\/python-range\/\">range() statement<\/a>. If you are accessing items in this list, an error may be raised.<br><\/p>\n\n\n\n<p>Consider the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>ages = [9, 10, 9]\n\nfor age in ages:\n\tprint(ages[age])<\/pre><\/div>\n\n\n\n<p>This code should print out all the values inside the \u201cages\u201d array. This array contains the ages of students in a middle school class. Let\u2019s run our program and see what happens:<br><\/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 4, in &lt;module&gt;\n\tprint(ages[age])\nIndexError: list index out of range<\/pre><\/div>\n\n\n\n<p>An error is raised. Let\u2019s add a print statement inside our loop to see the value of \u201cage\u201d in each iteration to see what has happened:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>ages = [9, 10, 9]\n\nfor age in ages:\n\tprint(age)\n\tprint(ages[age])<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>9\nTraceback (most recent call last):\n  File &quot;main.py&quot;, line 5, in &lt;module&gt;\n\tprint(ages[age])\nIndexError: list index out of range<\/pre><\/div>\n\n\n\n<p>The first age, 9, is printed to the console. However, the value of \u201cage\u201d is an actual value from \u201cages\u201d. It\u2019s not an index number. On the \u201cprint(ages[age])\u201d line of code, we\u2019re trying to access an age by its index number.<br><\/p>\n\n\n\n<p>When we run our code, it checks for: ages[9]. The value of \u201cage\u201d is 9 in the first iteration. There is no item in our \u201cages\u201d list with this value.<br><\/p>\n\n\n\n<p>To solve this problem, we can use a range() statement to iterate through our list of ages:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>ages = [9, 10, 9]\n\nfor age in range(0, len(ages)):\n\tprint(ages[age])<\/pre><\/div>\n\n\n\n<p>Let&#8217;s run our code again:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>9\n10\n9<\/pre><\/div>\n\n\n\n<p>All of the values from the \u201cages\u201d array are printed to the console. The range() statement creates a list of numbers in a particular range. In this case, the range [0, 1, 2] is created. These numbers can then be used to access values in \u201cages\u201d by their index number.<br><\/p>\n\n\n\n<p>Alternatively, we could use a \u201cfor&#8230;in\u201d loop without using indexing:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>ages = [9, 10, 9]\n\nfor age in ages:\n\tprint(age)<\/pre><\/div>\n\n\n\n<p>This code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>9\n10\n9<\/pre><\/div>\n\n\n\n<p>Our code does not try to access any values by index from the \u201cages\u201d array. Instead, our loop iterates through each value in the \u201cages\u201d array and prints it to the console.<\/p>\n\n\n\n<iframe loading=\"lazy\" frameborder=\"0\" width=\"100%\" height=\"400px\" src=\"https:\/\/repl.it\/@careerkarma\/indexerror-list-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 happen all the time. To solve the \u201cindexerror: list index out of range\u201d error, you should make sure that you\u2019re not trying to access a non-existent item in a list.<br><\/p>\n\n\n\n<p>If you are using a loop to access an item, make sure that loop accounts for the fact that lists are indexed from zero. If that does not solve the problem, check to make sure that you are using range() to access each item by its index value.<br><\/p>\n\n\n\n<p>Now you&#8217;re ready to solve the \u201cindexerror: list index out of range\u201d error like a <a href=\"https:\/\/careerkarma.com\/blog\/python-projects-beginners\/\">Python<\/a> expert!<\/p>\n","protected":false},"excerpt":{"rendered":"IndexErrors are one of the most common types of runtime errors in Python. They\u2019re raised when you try to access an index value inside a Python list that does not exist. In most cases, index errors are easy to resolve. You just need to do a little bit of debugging. In this tutorial, we\u2019re going&hellip;","protected":false},"author":240,"featured_media":18802,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-20630","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.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python indexerror: list index out of range Solution | Career Karma<\/title>\n<meta name=\"description\" content=\"On Career Karma, learn about the Python indexerror: list 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-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 index out of range Solution\" \/>\n<meta property=\"og:description\" content=\"On Career Karma, learn about the Python indexerror: list 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-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-01T07:44:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:57:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dMUt0X3f59Q-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"800\" \/>\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=\"5 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-index-out-of-range\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python indexerror: list index out of range Solution\",\"datePublished\":\"2020-08-01T07:44:00+00:00\",\"dateModified\":\"2023-12-01T11:57:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/\"},\"wordCount\":928,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dMUt0X3f59Q-unsplash.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/\",\"name\":\"Python indexerror: list index out of range Solution | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dMUt0X3f59Q-unsplash.jpg\",\"datePublished\":\"2020-08-01T07:44:00+00:00\",\"dateModified\":\"2023-12-01T11:57:14+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"On Career Karma, learn about the Python indexerror: list index out of range error, how the error works, and how to solve the error.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dMUt0X3f59Q-unsplash.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dMUt0X3f59Q-unsplash.jpg\",\"width\":1000,\"height\":800},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-indexerror-list-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 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\/#\/schema\/person\/image\/\",\"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 index out of range Solution | Career Karma","description":"On Career Karma, learn about the Python indexerror: list 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-index-out-of-range\/","og_locale":"en_US","og_type":"article","og_title":"Python indexerror: list index out of range Solution","og_description":"On Career Karma, learn about the Python indexerror: list index out of range error, how the error works, and how to solve the error.","og_url":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-08-01T07:44:00+00:00","article_modified_time":"2023-12-01T11:57:14+00:00","og_image":[{"width":1000,"height":800,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dMUt0X3f59Q-unsplash.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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python indexerror: list index out of range Solution","datePublished":"2020-08-01T07:44:00+00:00","dateModified":"2023-12-01T11:57:14+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/"},"wordCount":928,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dMUt0X3f59Q-unsplash.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/","url":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/","name":"Python indexerror: list index out of range Solution | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dMUt0X3f59Q-unsplash.jpg","datePublished":"2020-08-01T07:44:00+00:00","dateModified":"2023-12-01T11:57:14+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"On Career Karma, learn about the Python indexerror: list index out of range error, how the error works, and how to solve the error.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-index-out-of-range\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dMUt0X3f59Q-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/fabian-grohs-dMUt0X3f59Q-unsplash.jpg","width":1000,"height":800},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-indexerror-list-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 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\/#\/schema\/person\/image\/","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\/20630","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=20630"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/20630\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/18802"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=20630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=20630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=20630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}