{"id":113211,"date":"2020-05-21T13:06:18","date_gmt":"2020-05-21T13:06:18","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=8723"},"modified":"2020-05-21T13:06:18","modified_gmt":"2020-05-21T13:06:18","slug":"runtime-complexity-of-python-list-methods-easy-table-lookup","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2020\/05\/21\/runtime-complexity-of-python-list-methods-easy-table-lookup\/","title":{"rendered":"Runtime Complexity of Python List Methods [Easy Table Lookup]"},"content":{"rendered":"<p><strong>What&#8217;s the runtime complexity of various list methods? <\/strong><\/p>\n<p>The following table summarizes the runtime complexity of all list methods.<\/p>\n<p>Assume that the length of the data type is defined as <code>n<\/code> (that is&#8212;<code>len(data_type)<\/code>). You can now categorize the asymptotic complexity of the different complexity functions as follows:<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<thead>\n<tr>\n<th>Operation<\/th>\n<th>Example<\/th>\n<th>Complexity<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-index\/\" target=\"_blank\" rel=\"noreferrer noopener\">Index<\/a><\/td>\n<td><code>l[i]<\/code><\/td>\n<td><em>O(1)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/resolve-indexerror-list-assignment-index-out-of-range\/\" target=\"_blank\" rel=\"noreferrer noopener\">Store<\/a><\/td>\n<td><code>l[i] = 42<\/code><\/td>\n<td><em>O(1)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-length-whats-the-runtime-complexity-of-len\/\" target=\"_blank\" rel=\"noreferrer noopener\">Length<\/a><\/td>\n<td><code>len(l)<\/code><\/td>\n<td><em>O(1)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-append\/\" target=\"_blank\" rel=\"noreferrer noopener\">Append<\/a><\/td>\n<td><code>l.append(42)<\/code><\/td>\n<td><em>O(1)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-pop\/\" target=\"_blank\" rel=\"noreferrer noopener\">Pop<\/a><\/td>\n<td><code>l.pop()<\/code><\/td>\n<td><em>O(1)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-clear\/\" target=\"_blank\" rel=\"noreferrer noopener\">Clear<\/a><\/td>\n<td><code>l.clear()<\/code><\/td>\n<td><em>O(1)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/introduction-to-slicing-in-python\/\" target=\"_blank\">Slicin<\/a><a href=\"https:\/\/blog.finxter.com\/introduction-to-slicing-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">g<\/a><\/td>\n<td><code>l[a:b]<\/code><\/td>\n<td><em>O(b-a)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-extend\/\" target=\"_blank\" rel=\"noreferrer noopener\">Extend<\/a><\/td>\n<td><code>l1.extend(l2)<\/code><\/td>\n<td><em>O(len(l1)+len(l2))<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\" rel=\"noreferrer noopener\">Constructor<\/a><\/td>\n<td><code>list(iter)<\/code><\/td>\n<td><em>O(len(iter))<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-string-contains\/\" target=\"_blank\" rel=\"noreferrer noopener\">Equality<\/a><\/td>\n<td><code>l1 == l2<\/code><\/td>\n<td><em>O(n)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-slice-assignment\/\" target=\"_blank\" rel=\"noreferrer noopener\">Slice Assign<\/a><\/td>\n<td><code>l[a:b] = ...<\/code><\/td>\n<td><em>O(n)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-remove\/\" target=\"_blank\" rel=\"noreferrer noopener\">Delete<\/a><\/td>\n<td><code>del l[i]<\/code><\/td>\n<td><em>O(n)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-remove\/\" target=\"_blank\" rel=\"noreferrer noopener\">Remove<\/a><\/td>\n<td><code>l.remove(...)<\/code><\/td>\n<td><em>O(n)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\" rel=\"noreferrer noopener\">Membership<\/a><\/td>\n<td><code>x in l \/ x not in l<\/code><\/td>\n<td><em>O(n)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-copy\/\" target=\"_blank\" rel=\"noreferrer noopener\">Copy<\/a><\/td>\n<td><code>l.copy()<\/code><\/td>\n<td><em>O(n)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-pop\/\" target=\"_blank\" rel=\"noreferrer noopener\">Pop<\/a><\/td>\n<td><code>l.pop(0)<\/code><\/td>\n<td><em>O(n)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/how-to-find-the-minimum-of-a-list-of-lists-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">Min<\/a><\/td>\n<td><code>min(l)<\/code><\/td>\n<td><em>O(n)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/how-to-find-the-max-of-list-of-lists-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">Max<\/a><\/td>\n<td><code>max(l)<\/code><\/td>\n<td><em>O(n)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-reverse\/\" target=\"_blank\" rel=\"noreferrer noopener\">Reverse<\/a><\/td>\n<td><code>l.reverse()<\/code><\/td>\n<td><em>O(n)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-loops\/\" target=\"_blank\" rel=\"noreferrer noopener\">Iterate<\/a><\/td>\n<td><code>for x in l:<\/code><\/td>\n<td><em>O(n)<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-sort\/\" target=\"_blank\" rel=\"noreferrer noopener\">Sort<\/a><\/td>\n<td><code>l.sort()<\/code><\/td>\n<td><em>O(n log(n))<\/em><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/blog.finxter.com\/python-list-concatenation-add-vs-inplace-add-vs-extend\/\" target=\"_blank\" rel=\"noreferrer noopener\">Multiply<\/a><\/td>\n<td><code>l*k<\/code><\/td>\n<td><em>O(n k)<\/em><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>Need to learn more about these methods? Watch me giving you a quick overview of all Python list methods:<\/p>\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<div class=\"wp-block-embed__wrapper\">\n<div class=\"ast-oembed-container\"><iframe loading=\"lazy\" title=\"Python List Methods\" width=\"1400\" height=\"788\" src=\"https:\/\/www.youtube.com\/embed\/4j8B9a_kZY4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/div>\n<\/div>\n<\/figure>\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-list-methods\/\" target=\"_blank\">You can read more about all methods in my detailed tutorial on the Finxter blog.<\/a><\/p>\n<p>Here&#8217;s your free PDF cheat sheet showing you all Python list methods on one simple page. Click the image to download the high-resolution PDF file, print it, and post it to your office wall:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/04\/Python-List-Methods-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/04\/Python-List-Methods-Cheat-Sheet.jpg\" alt=\"\" class=\"wp-image-7544\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/04\/Python-List-Methods-Cheat-Sheet.jpg 670w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/04\/Python-List-Methods-Cheat-Sheet-231x300.jpg 231w\" sizes=\"(max-width: 670px) 100vw, 670px\" \/><\/a><\/figure>\n<\/div>\n<div class=\"wp-block-buttons aligncenter\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-background has-vivid-cyan-blue-background-color\" href=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/04\/Python-List-Methods-Cheat-Sheet.pdf\" style=\"border-radius:9px\" target=\"_blank\" rel=\"noreferrer noopener\">Instant PDF Download [100% FREE]<\/a><\/div>\n<\/div>\n<h2>Where to Go From Here?<\/h2>\n<p>Enough theory, let\u2019s get some practice!<\/p>\n<p>To become successful in coding, you need to get out there and solve real problems for real people. That\u2019s how you can become a six-figure earner easily. And that\u2019s how you polish the skills you really need in practice. After all, what\u2019s the use of learning theory that nobody ever needs?<\/p>\n<p><strong>Practice projects is how you sharpen your saw in coding!<\/strong><\/p>\n<p>Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?<\/p>\n<p>Then become a Python freelance developer! It\u2019s the best way of approaching the task of improving your Python skills\u2014even if you are a complete beginner.<\/p>\n<p>Join my free webinar <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/webinar-freelancer\/\" target=\"_blank\">\u201cHow to Build Your High-Income Skill Python\u201d<\/a> and watch how I grew my coding business online and how you can, too\u2014from the comfort of your own home.<\/p>\n<p><a href=\"https:\/\/blog.finxter.com\/webinar-freelancer\/\" target=\"_blank\" rel=\"noreferrer noopener\">Join the free webinar now!<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What&#8217;s the runtime complexity of various list methods? The following table summarizes the runtime complexity of all list methods. Assume that the length of the data type is defined as n (that is&#8212;len(data_type)). You can now categorize the asymptotic complexity of the different complexity functions as follows: Operation Example Complexity Index l[i] O(1) Store l[i] [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-113211","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/113211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=113211"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/113211\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=113211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=113211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=113211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}