{"id":1855,"date":"2009-02-13T08:34:05","date_gmt":"2009-02-13T08:34:05","guid":{"rendered":"http:\/\/justthesam.com\/2009\/02\/python-annoyance-not-returning-self\/"},"modified":"2009-02-13T08:34:05","modified_gmt":"2009-02-13T08:34:05","slug":"python-annoyance-not-returning-self","status":"publish","type":"post","link":"https:\/\/justthesam.com\/?p=1855","title":{"rendered":"Python Annoyance &#8211; Not Returning self"},"content":{"rendered":"<p>I&#39;ve noticed that a lot of the standard Python methods on lists and dictionaries don&#39;t return anything at all &#8211; they simply modify self and return nothing.<\/p>\n<div>\n<div><span style=\"font-family: Courier;\">&gt;&gt;&gt; l = [1,2,3]<\/span><\/div>\n<div><span style=\"font-family: Courier;\">&gt;&gt;&gt; r = l.reverse()<\/span><\/div>\n<div>\n<div><span style=\"font-family: Courier;\">&gt;&gt;&gt; print l<\/span><\/div>\n<div><span style=\"font-family: Courier;\">[3, 2, 1]<\/span><\/div>\n<\/div>\n<div><span style=\"font-family: Courier;\">&gt;&gt;&gt; print r<\/span><\/div>\n<div><span style=\"font-family: Courier;\">None<\/span><\/div>\n<p><\/p>\n<div>This is becoming extremely frustrating as it prevents chaining of method calls, which would be possible if only self was returned. This keeps catching me out if I attempt to r<span style=\"font-family: Courier;\">eturn some_list.reverse()<\/span> or <span style=\"font-family: Courier;\">dict = {&#39;foo&#39;:bar, &#39;x&#39;:y}.update(some_other_dict)<\/span> as I end up with None when I expected Something.<\/div>\n<p><\/p>\n<div>It&#39;s the little details that make a language a joy or a chore.<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I&#39;ve noticed that a lot of the standard Python methods on lists and dictionaries don&#39;t return anything at all &#8211; they simply modify self and return nothing. &gt;&gt;&gt; l = [1,2,3] &gt;&gt;&gt; r = l.reverse() &gt;&gt;&gt; print l [3, 2, 1] &gt;&gt;&gt; print r None This is becoming extremely frustrating as it prevents chaining of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,33],"tags":[],"class_list":["post-1855","post","type-post","status-publish","format-standard","hentry","category-programming","category-webtech"],"_links":{"self":[{"href":"https:\/\/justthesam.com\/index.php?rest_route=\/wp\/v2\/posts\/1855","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/justthesam.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/justthesam.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/justthesam.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/justthesam.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1855"}],"version-history":[{"count":0,"href":"https:\/\/justthesam.com\/index.php?rest_route=\/wp\/v2\/posts\/1855\/revisions"}],"wp:attachment":[{"href":"https:\/\/justthesam.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/justthesam.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/justthesam.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}