{"id":7277,"date":"2025-03-12T06:10:52","date_gmt":"2025-03-12T06:10:52","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7277"},"modified":"2025-03-19T06:27:56","modified_gmt":"2025-03-19T06:27:56","slug":"how-to-randomly-select-item-from-python-list","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/","title":{"rendered":"How to Randomly Select Item from Python List"},"content":{"rendered":"\n<p>Python developers may sometimes need to randomly select one or more items from a Python list. It can be difficult to device a solution from scratch, for this purpose. Luckily there are several easy ways to pick a random item from a Python list. In this article, we will learn how to randomly select item from Python list.<\/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-randomly-select-item-from-python-list\/#Why_Randomly_Select_Item_from_Python_List\" >Why Randomly Select Item from Python List<\/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-randomly-select-item-from-python-list\/#How_to_Randomly_Select_Item_from_Python_List\" >How to Randomly Select Item from Python List<\/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-randomly-select-item-from-python-list\/#1_Using_randomchoice\" >1. Using random.choice()<\/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-randomly-select-item-from-python-list\/#2_Using_randomsample\" >2. Using random.sample()<\/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-randomly-select-item-from-python-list\/#3_Using_randomrandom\" >3. Using random.random()<\/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-randomly-select-item-from-python-list\/#4_Using_randomrandrange\" >4. Using random.randrange()<\/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-randomly-select-item-from-python-list\/#5_Using_randomrandint\" >5. Using random.randint()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_Randomly_Select_Item_from_Python_List\"><\/span>Why Randomly Select Item from Python List<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you need to display a random image or blog post on your website, then you may need to select a random item from a list of image or posts. This is a use case where you need to randomly select item from Python list. Another use case is for statistical analysis where you need to select a random sample from a larger data set. In this case also, you need to randomly select item from Python list.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Randomly_Select_Item_from_Python_List\"><\/span>How to Randomly Select Item from Python List<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are several powerful Python libraries that offer many useful functions to generate a random number. Among them, <em>random<\/em> library is one of the most popular libraries. It offers several functions to help you select one or more random items from a Python list, in different ways.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_randomchoice\"><\/span>1. Using random.choice()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Random library provides choice() function that returns a random item from a list of items in Python. Let us say you have the following Python list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import random<br>a = [1, 2, 3, 4, 5]<br>print(random.choice(a)) # output is a random item<\/pre>\n\n\n\n<p>In the above code, we first import random library. Then we call random.choice() function with list name as the first argument. Every time you can random.choice() function, it will return a different output.<\/p>\n\n\n\n<p>If you want to select multiple items from a list of items, then you need to use random.choices() instead. It takes two arguments &#8211; the list and number of items to be selected. While specifying the number of items, you need to specify the keyword &#8216;k&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import random<br>a = [1, 2, 3, 4, 5]<br>print(random.choices(a, k=2)) # output is a random list of 2 items<\/pre>\n\n\n\n<p>Every time you run the above code, it will print a list of 2 random items from original list. Please note, this list may contain repetitions. If you do not want any repetition in your list of randomly selected items, then you need to use random.sample() function described below.<\/p>\n\n\n\n<p>Also, when you select multiple items using this method, then the result items can be in any order. Even the repeated items can be located in any order. Sometimes, only one item may be repeated, sometimes multiple items may be repeated.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_randomsample\"><\/span>2. Using random.sample()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Random.sample() function can be used to select one or more items from a list of items. When you select multiple items, it will return a list of randomly selected items, without any repetition. It has the following syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">random.sample(list_name, no_of_items)<\/pre>\n\n\n\n<p>Here is an example to select a single item from a list of items.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import random<br>a = [1, 2, 3, 4, 5]<br>print(random.sample(a,1)) # output is a random list of 1 item such as [2]<\/pre>\n\n\n\n<p>Here is an example to randomly select multiple items from a Python list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import random<br>a = [1, 2, 3, 4, 5]<br>print(random.sample(a,3)) # [1, 4, 2]<\/pre>\n\n\n\n<p>Please note, whether you select one random item, or multiple random items, it will always return the result as a list.<\/p>\n\n\n\n<p>Also, when you select multiple items, then the result may contain items in any order. They need not be in the same order as they are present in original list.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_randomrandom\"><\/span>3. Using random.random()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Random.random() function returns a random floating point number between 0 and 1. It can be used to get a random item from Python list by multiplying it with the length of Python list and typecasting the result to an integer to obtain random index. This index can be used to pick random item from Python list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import random<br>a = [1, 2, 3, 4, 5]<br>random_number = random.random()<br>random_index = int(random_number * len(a))<br>random_item = a[random_index]<br>print(random_item)<br><\/pre>\n\n\n\n<p>In the above code, first we calculate a random number using random.random() function. We then multiply it with the length of our list. We convert the result into an integer using int(), to obtain random index. Lastly, we obtain the random item using this random index.<\/p>\n\n\n\n<p>In fact, this used to be one of the most commonly used methods to generate random number or pick rando item from a Python list, before the advent of out of the box functions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_randomrandrange\"><\/span>4. Using random.randrange()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Random.randrange() function allows you to generate a random number within a range. It takes one argument and returns a random number between 0 and that number. In this case, we directly use this function to get a random index value, and use this index to get random item.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import random<br>a = [1, 2, 3, 4, 5]<br>random_index = random.randrange(len(a))<br>random_item = a[random_index]<br>print(random_item)<\/pre>\n\n\n\n<p>In the above code, we can call randrange() function on length of our list. It returns an index >= 0 and length of our list-1. We use it to select the random item.<\/p>\n\n\n\n<p>This method allows you to directly get a random index to obtain a random item. If you want to obtain a list of multiple random items from a given list then you need to run a loop whereby in each iteration, you call this randrange() function and get a random item. Here is an example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import random<br>a = [1, 2, 3, 4, 5]<br>b = []<br>n=3<br>for i in range(n):<br>    random_index = random.randrange(len(a))<br>    random_item = a[random_index]<br>    b.append(random_item)<br>print(b)<\/pre>\n\n\n\n<p>In the above code, we need to get 3 random items from our list. So we create a blank list b to store the result. We run a loop with 3 iterations. In each iteration, we get a random item from our list and push it to our result list. Please note, the order of items in the result list need not be same as that of original list. This is because in each iteration, you may get a different index. Sometimes, there may also be repetition, if the randrange() returns the same index.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_randomrandint\"><\/span>5. Using random.randint()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Random.randint() generates a random number between 2 specific numbers. We use this function to get a random number between 0 and the length of our list. This will generate a random index. We use this index to get random element.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import random<br>a = [1, 2, 3, 4, 5]<br>random_index = random.randint(0,len(a)-1)<br>random_item = a[random_index]<br>print(random_item)<\/pre>\n\n\n\n<p>If you want to pick multiple random items from a list, you can run a loop for the number of random items. In each loop iteration, you can generate a random index and use it to get a random item. One by one, you can append each of these random items to a result list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import random<br>a = [1, 2, 3, 4, 5]<br>b = []<br>n=3<br>for i in range(n):<br>    random_index = random.randint(0,len(a)-1)<br>    random_item = a[random_index]<br>    b.append(random_item)<br>print(b)<\/pre>\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 randomly select item from Python list. We have learnt how to select single as well as multiple items from a list. You can use any of these methods as per your requirement. If you need only one random item from a list, you can use random.choice() function. If you want to pick multiple random items, then you can use random.choices(), if you are ok with repetitions in your selection. If you do not want any repetition in randomly selected items, then you can use random.sample() function.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-delete-column-in-pandas-dataframe\/\">How to Delete Column in Pandas Dataframe<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/\">How to Sort Python Dictionary By Value<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-rename-columns-in-pandas\/\">How to Rename Columns in Pandas<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you may need to pick random items from Python list. Here is how to randomly select item from Python list.<\/p>\n","protected":false},"author":1,"featured_media":7302,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[395],"class_list":["post-7277","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-random-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Randomly Select Item from Python List - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes you may need to pick random items from Python list. Here is how to randomly select item from Python list.\" \/>\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-randomly-select-item-from-python-list\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Randomly Select Item from Python List - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes you may need to pick random items from Python list. Here is how to randomly select item from Python list.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/\" \/>\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=\"2025-03-12T06:10:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-19T06:27:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/get-random-element-from-list-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"297\" \/>\n\t<meta property=\"og:image:height\" content=\"199\" \/>\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=\"6 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-randomly-select-item-from-python-list\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Randomly Select Item from Python List\",\"datePublished\":\"2025-03-12T06:10:52+00:00\",\"dateModified\":\"2025-03-19T06:27:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/\"},\"wordCount\":1114,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/get-random-element-from-list-python.jpg?fit=297%2C199&ssl=1\",\"keywords\":[\"random item\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/\",\"name\":\"How to Randomly Select Item from Python List - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/get-random-element-from-list-python.jpg?fit=297%2C199&ssl=1\",\"datePublished\":\"2025-03-12T06:10:52+00:00\",\"dateModified\":\"2025-03-19T06:27:56+00:00\",\"author\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes you may need to pick random items from Python list. Here is how to randomly select item from Python list.\",\"breadcrumb\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/get-random-element-from-list-python.jpg?fit=297%2C199&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/get-random-element-from-list-python.jpg?fit=297%2C199&ssl=1\",\"width\":297,\"height\":199,\"caption\":\"randomly select item from Python list\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ubiq.co\/tech-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Randomly Select Item from Python List\"}]},{\"@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 Randomly Select Item from Python List - Ubiq BI","description":"Sometimes you may need to pick random items from Python list. Here is how to randomly select item from Python list.","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-randomly-select-item-from-python-list\/","og_locale":"en_US","og_type":"article","og_title":"How to Randomly Select Item from Python List - Ubiq BI","og_description":"Sometimes you may need to pick random items from Python list. Here is how to randomly select item from Python list.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-03-12T06:10:52+00:00","article_modified_time":"2025-03-19T06:27:56+00:00","og_image":[{"width":297,"height":199,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/get-random-element-from-list-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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Randomly Select Item from Python List","datePublished":"2025-03-12T06:10:52+00:00","dateModified":"2025-03-19T06:27:56+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/"},"wordCount":1114,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/get-random-element-from-list-python.jpg?fit=297%2C199&ssl=1","keywords":["random item"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/","name":"How to Randomly Select Item from Python List - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/get-random-element-from-list-python.jpg?fit=297%2C199&ssl=1","datePublished":"2025-03-12T06:10:52+00:00","dateModified":"2025-03-19T06:27:56+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes you may need to pick random items from Python list. Here is how to randomly select item from Python list.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/get-random-element-from-list-python.jpg?fit=297%2C199&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/get-random-element-from-list-python.jpg?fit=297%2C199&ssl=1","width":297,"height":199,"caption":"randomly select item from Python list"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-randomly-select-item-from-python-list\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Randomly Select Item from Python List"}]},{"@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\/2025\/03\/get-random-element-from-list-python.jpg?fit=297%2C199&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Tn","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7277","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=7277"}],"version-history":[{"count":31,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7277\/revisions"}],"predecessor-version":[{"id":7381,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7277\/revisions\/7381"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7302"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}