{"id":38247,"date":"2025-08-15T11:41:42","date_gmt":"2025-08-15T18:41:42","guid":{"rendered":"https:\/\/cloudinary.com\/blog\/?p=38247"},"modified":"2025-08-22T12:02:25","modified_gmt":"2025-08-22T19:02:25","slug":"how-to-get-the-index-of-an-item-in-a-list-in-python","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/","title":{"rendered":"How to Get the Index of an Item in a List in Python?"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Question:<\/h3>\n\n\n\n<p>Hi folks,<\/p>\n\n\n\n<p>I&#8217;m working on a Python script where I have a list of image filenames, and I want to find the position (index) of a specific image in that list. I heard about the <code>.index()<\/code> method but I&#8217;m not sure how it works exactly.<\/p>\n\n\n\n<p>Could someone explain how to get the index of an item in a list in Python? Also, what happens if the item isn\u2019t in the list? Are there safer ways to handle that?<\/p>\n\n\n\n<p>Thanks in advance!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Answer:<\/h3>\n\n\n\n<p>Great question! Getting the index of an item in a list is a fundamental operation in Python and is extremely useful for tasks like locating images in a gallery, manipulating tag lists, or updating metadata dynamically in systems like Cloudinary.<\/p>\n\n\n\n<p>Let\u2019s dive into how to do this properly and safely, with examples relevant to image management.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Basic Method: <code>.index()<\/code><\/h2>\n\n\n\n<p>The simplest way to get the index of an item in a list is to use the <code>.index()<\/code> method:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">images = &#91;<span class=\"hljs-string\">'img1.jpg'<\/span>, <span class=\"hljs-string\">'img2.jpg'<\/span>, <span class=\"hljs-string\">'img3.jpg'<\/span>, <span class=\"hljs-string\">'img4.jpg'<\/span>]\n\nposition = images.index(<span class=\"hljs-string\">'img3.jpg'<\/span>)\n\n<span class=\"hljs-keyword\">print<\/span>(position)\u00a0 <span class=\"hljs-comment\"># Output: 2<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ul class=\"wp-block-list\">\n<li><code>.index(item)<\/code> returns the <strong>zero-based<\/strong> index of the first matching item.<\/li>\n\n\n\n<li>If the item is not found, Python raises a <code>ValueError<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Handling Missing Items: Avoid <code>ValueError<\/code><\/h2>\n\n\n\n<p>If you try to get the index of an item that doesn\u2019t exist, like:<\/p>\n\n\n\n<p><code>images.index('img5.jpg')&nbsp; # Raises ValueError<\/code><\/p>\n\n\n\n<p>Python throws:<\/p>\n\n\n\n<p><code>ValueError: 'img5.jpg' is not in list<\/code><\/p>\n\n\n\n<p>To handle this gracefully, use a <code>try-except<\/code> block:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-keyword\">try<\/span>:\n\n\u00a0\u00a0\u00a0\u00a0position = images.index(<span class=\"hljs-string\">'img5.jpg'<\/span>)\n\n\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">print<\/span>(f<span class=\"hljs-string\">\"Found at position {position}\"<\/span>)\n\nexcept ValueError:\n\n\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Image not found in the list\"<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Safer Alternative: Check First With <code>in<\/code><\/h2>\n\n\n\n<p>Before calling <code>.index()<\/code>, you can check if the item exists:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-keyword\">if<\/span> <span class=\"hljs-string\">'img5.jpg'<\/span> in images:\n\n\u00a0\u00a0\u00a0\u00a0position = images.index(<span class=\"hljs-string\">'img5.jpg'<\/span>)\n\n\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">print<\/span>(f<span class=\"hljs-string\">\"Found at position {position}\"<\/span>)\n\n<span class=\"hljs-keyword\">else<\/span>:\n\n\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Image not found\"<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Use Case: Find Index and Update Metadata<\/h2>\n\n\n\n<p>Say you want to update the tags for a particular image:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">images = &#91;<span class=\"hljs-string\">'img1.jpg'<\/span>, <span class=\"hljs-string\">'img2.jpg'<\/span>, <span class=\"hljs-string\">'img3.jpg'<\/span>]\n\ntags = &#91;&#91;<span class=\"hljs-string\">'sunset'<\/span>], &#91;<span class=\"hljs-string\">'portrait'<\/span>], &#91;<span class=\"hljs-string\">'landscape'<\/span>]]\n\ntarget = <span class=\"hljs-string\">'img2.jpg'<\/span>\n\n<span class=\"hljs-keyword\">if<\/span> target in images:\n\n\u00a0\u00a0\u00a0\u00a0idx = images.index(target)\n\n\u00a0\u00a0\u00a0\u00a0tags&#91;idx].append(<span class=\"hljs-string\">'featured'<\/span>)\n\n\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">print<\/span>(f<span class=\"hljs-string\">\"Updated tags for {target}: {tags&#91;idx]}\"<\/span>)\n\n<span class=\"hljs-keyword\">else<\/span>:\n\n\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Image not found\"<\/span>)\n\n<span class=\"hljs-comment\"># Output: Updated tags for img2.jpg: &#91;'portrait', 'featured']<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Find All Indices for Duplicate Items<\/h2>\n\n\n\n<p>Lists can have duplicates. <code>.index()<\/code> only returns the first occurrence.<\/p>\n\n\n\n<p>If you want all positions where an item occurs:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">images = &#91;<span class=\"hljs-string\">'img1.jpg'<\/span>, <span class=\"hljs-string\">'img2.jpg'<\/span>, <span class=\"hljs-string\">'img3.jpg'<\/span>, <span class=\"hljs-string\">'img2.jpg'<\/span>, <span class=\"hljs-string\">'img4.jpg'<\/span>]\n\ntarget = <span class=\"hljs-string\">'img2.jpg'<\/span>\n\npositions = &#91;i <span class=\"hljs-keyword\">for<\/span> i, x in enumerate(images) <span class=\"hljs-keyword\">if<\/span> x == target]\n\n<span class=\"hljs-keyword\">print<\/span>(positions)\u00a0 <span class=\"hljs-comment\"># Output: &#91;1, 3]<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This is useful when images appear multiple times in a dataset or batch.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bonus: Using <code>enumerate()<\/code> for Index and Value<\/h2>\n\n\n\n<p>Sometimes you want to iterate and find index and value simultaneously:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-keyword\">for<\/span> idx, image in enumerate(images):\n\n\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">if<\/span> image == <span class=\"hljs-string\">'img3.jpg'<\/span>:\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">print<\/span>(f<span class=\"hljs-string\">\"Found {image} at index {idx}\"<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\"><strong>TL;DR: Python Get Index of Item in List<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Task<\/strong><\/td><td><strong>Code Example<\/strong><\/td><td><strong>Notes<\/strong><\/td><\/tr><tr><td>Get the index of an existing item<\/td><td><code>list.index(item)<\/code><\/td><td>Raises <code>ValueError<\/code> if not found<\/td><\/tr><tr><td>Check existence first<\/td><td><code>if item in list:<\/code> + <code>list.index(item)<\/code><\/td><td>Avoids errors<\/td><\/tr><tr><td>Handle missing safely<\/td><td>Use <code>try-except ValueError<\/code><\/td><td>Good for unpredictable input<\/td><\/tr><tr><td>Find all indices for duplicates<\/td><td><code>[i for i, x in enumerate(list) if x == item]<\/code><\/td><td>Returns list of positions<\/td><\/tr><tr><td>Iterate with index<\/td><td><code>for idx, val in enumerate(list):<\/code><\/td><td>Combines index &amp; value<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Real-World Scenario: Cloudinary Image Management<\/h2>\n\n\n\n<p>Imagine you maintain a list of Cloudinary public IDs and want to batch update images based on position:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">public_ids = &#91;<span class=\"hljs-string\">'abc123'<\/span>, <span class=\"hljs-string\">'def456'<\/span>, <span class=\"hljs-string\">'ghi789'<\/span>]\n\nupdates = {<span class=\"hljs-string\">'def456'<\/span>: {<span class=\"hljs-string\">'tags'<\/span>: &#91;<span class=\"hljs-string\">'new'<\/span>]}, <span class=\"hljs-string\">'xyz999'<\/span>: {<span class=\"hljs-string\">'tags'<\/span>: &#91;<span class=\"hljs-string\">'old'<\/span>]}}\n\n<span class=\"hljs-keyword\">for<\/span> pid in updates:\n\n\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">if<\/span> pid in public_ids:\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0idx = public_ids.index(pid)\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">print<\/span>(f<span class=\"hljs-string\">\"Updating {pid} at position {idx}\"<\/span>)\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-comment\"># Call Cloudinary API with public_ids&#91;idx]<\/span>\n\n\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">else<\/span>:\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<span class=\"hljs-keyword\">print<\/span>(f<span class=\"hljs-string\">\"{pid} not found in current images\"<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Bonus Tip: Index of Item in Nested Lists<\/h2>\n\n\n\n<p>If your data structure is more complex, like a list of lists:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">image_data = &#91;\n\n\u00a0\u00a0\u00a0\u00a0&#91;<span class=\"hljs-string\">'img1.jpg'<\/span>, <span class=\"hljs-string\">'sunset'<\/span>],\n\n\u00a0\u00a0\u00a0\u00a0&#91;<span class=\"hljs-string\">'img2.jpg'<\/span>, <span class=\"hljs-string\">'portrait'<\/span>],\n\n\u00a0\u00a0\u00a0\u00a0&#91;<span class=\"hljs-string\">'img3.jpg'<\/span>, <span class=\"hljs-string\">'landscape'<\/span>]\n\n]\n\ntarget = <span class=\"hljs-string\">'img2.jpg'<\/span>\n\nidx = next((i <span class=\"hljs-keyword\">for<\/span> i, v in enumerate(image_data) <span class=\"hljs-keyword\">if<\/span> v&#91;<span class=\"hljs-number\">0<\/span>] == target), <span class=\"hljs-number\">-1<\/span>)\n\n<span class=\"hljs-keyword\">print<\/span>(idx)\u00a0 <span class=\"hljs-comment\"># Output: 1<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This finds the index of the sublist where the first element matches the target.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\n\n\n\n<p>Using <code>.index()<\/code> is straightforward but requires careful error handling. Whether you\u2019re managing simple lists of images or complex datasets, combining <code>.index()<\/code> with <code>in<\/code> checks or exception handling makes your code robust.<\/p>\n\n\n\n<p>Remember:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use <code>try-except<\/code> or <code>in<\/code> to avoid crashes.<\/li>\n\n\n\n<li>For duplicates, use list comprehensions with <code>enumerate()<\/code>.<\/li>\n<\/ul>\n\n\n\n<p>Leverage <code>enumerate()<\/code> to process indices and values together.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Question: Hi folks, I&#8217;m working on a Python script where I have a list of image filenames, and I want to find the position (index) of a specific image in that list. I heard about the .index() method but I&#8217;m not sure how it works exactly. Could someone explain how to get the index of [&hellip;]<\/p>\n","protected":false},"author":112,"featured_media":38341,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":""},"categories":[1],"tags":[423],"class_list":["post-38247","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-questions"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.6 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Get the Index of an Item in a List in Python?<\/title>\n<meta name=\"description\" content=\"Question: Hi folks, I&#039;m working on a Python script where I have a list of image filenames, and I want to find the position (index) of a specific image in\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-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 Get the Index of an Item in a List in Python?\" \/>\n<meta property=\"og:description\" content=\"Question: Hi folks, I&#039;m working on a Python script where I have a list of image filenames, and I want to find the position (index) of a specific image in\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-15T18:41:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-22T19:02:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1756252703\/blog-generic_python\/blog-generic_python.jpg?_i=AA\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"1100\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"jeromehidalgosanz\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"NewsArticle\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/\"},\"author\":{\"name\":\"jeromehidalgosanz\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/87d542a9f3b665a624072d59748ecce1\"},\"headline\":\"How to Get the Index of an Item in a List in Python?\",\"datePublished\":\"2025-08-15T18:41:42+00:00\",\"dateModified\":\"2025-08-22T19:02:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/\"},\"wordCount\":468,\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1756252703\/blog-generic_python\/blog-generic_python.jpg?_i=AA\",\"keywords\":[\"Questions\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2025\",\"copyrightHolder\":{\"@id\":\"https:\/\/cloudinary.com\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/\",\"url\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/\",\"name\":\"How to Get the Index of an Item in a List in Python?\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1756252703\/blog-generic_python\/blog-generic_python.jpg?_i=AA\",\"datePublished\":\"2025-08-15T18:41:42+00:00\",\"dateModified\":\"2025-08-22T19:02:25+00:00\",\"description\":\"Question: Hi folks, I'm working on a Python script where I have a list of image filenames, and I want to find the position (index) of a specific image in\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#primaryimage\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1756252703\/blog-generic_python\/blog-generic_python.jpg?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1756252703\/blog-generic_python\/blog-generic_python.jpg?_i=AA\",\"width\":2000,\"height\":1100},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudinary.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Get the Index of an Item in a List in Python?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"name\":\"Cloudinary Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudinary.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\",\"name\":\"Cloudinary Blog\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"width\":312,\"height\":60,\"caption\":\"Cloudinary Blog\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/87d542a9f3b665a624072d59748ecce1\",\"name\":\"jeromehidalgosanz\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/21bd8bba3087dbeff42280210669b975ea98b59ca9f427e828f4b59c4bae58dd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/21bd8bba3087dbeff42280210669b975ea98b59ca9f427e828f4b59c4bae58dd?s=96&d=mm&r=g\",\"caption\":\"jeromehidalgosanz\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Get the Index of an Item in a List in Python?","description":"Question: Hi folks, I'm working on a Python script where I have a list of image filenames, and I want to find the position (index) of a specific image in","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:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Get the Index of an Item in a List in Python?","og_description":"Question: Hi folks, I'm working on a Python script where I have a list of image filenames, and I want to find the position (index) of a specific image in","og_url":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/","og_site_name":"Cloudinary Blog","article_published_time":"2025-08-15T18:41:42+00:00","article_modified_time":"2025-08-22T19:02:25+00:00","og_image":[{"width":2000,"height":1100,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1756252703\/blog-generic_python\/blog-generic_python.jpg?_i=AA","type":"image\/jpeg"}],"author":"jeromehidalgosanz","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/"},"author":{"name":"jeromehidalgosanz","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/87d542a9f3b665a624072d59748ecce1"},"headline":"How to Get the Index of an Item in a List in Python?","datePublished":"2025-08-15T18:41:42+00:00","dateModified":"2025-08-22T19:02:25+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/"},"wordCount":468,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1756252703\/blog-generic_python\/blog-generic_python.jpg?_i=AA","keywords":["Questions"],"inLanguage":"en-US","copyrightYear":"2025","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/","url":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/","name":"How to Get the Index of an Item in a List in Python?","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1756252703\/blog-generic_python\/blog-generic_python.jpg?_i=AA","datePublished":"2025-08-15T18:41:42+00:00","dateModified":"2025-08-22T19:02:25+00:00","description":"Question: Hi folks, I'm working on a Python script where I have a list of image filenames, and I want to find the position (index) of a specific image in","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1756252703\/blog-generic_python\/blog-generic_python.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1756252703\/blog-generic_python\/blog-generic_python.jpg?_i=AA","width":2000,"height":1100},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-get-the-index-of-an-item-in-a-list-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Get the Index of an Item in a List in Python?"}]},{"@type":"WebSite","@id":"https:\/\/cloudinary.com\/blog\/#website","url":"https:\/\/cloudinary.com\/blog\/","name":"Cloudinary Blog","description":"","publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudinary.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudinary.com\/blog\/#organization","name":"Cloudinary Blog","url":"https:\/\/cloudinary.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","width":312,"height":60,"caption":"Cloudinary Blog"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/87d542a9f3b665a624072d59748ecce1","name":"jeromehidalgosanz","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/21bd8bba3087dbeff42280210669b975ea98b59ca9f427e828f4b59c4bae58dd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21bd8bba3087dbeff42280210669b975ea98b59ca9f427e828f4b59c4bae58dd?s=96&d=mm&r=g","caption":"jeromehidalgosanz"}}]}},"jetpack_featured_media_url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1756252703\/blog-generic_python\/blog-generic_python.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/38247","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/users\/112"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/comments?post=38247"}],"version-history":[{"count":2,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/38247\/revisions"}],"predecessor-version":[{"id":38419,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/38247\/revisions\/38419"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/38341"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=38247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=38247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=38247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}