{"id":1833,"date":"2016-04-06T22:05:50","date_gmt":"2016-04-07T05:05:50","guid":{"rendered":"http:\/\/zackmdavis.net\/blog\/?p=1833"},"modified":"2016-04-06T22:05:50","modified_gmt":"2016-04-07T05:05:50","slug":"subzero","status":"publish","type":"post","link":"http:\/\/zackmdavis.net\/blog\/2016\/04\/subzero\/","title":{"rendered":"Subzero"},"content":{"rendered":"<p>Python has this elegant destructuring-assignment iterable-unpacking syntax that every serious Pythonista and her dog tends to use where\u00ebver possible. So where a novice might write<\/p>\n<pre><code>split_address = address.split(':')\r\nhost = split_address[0]\r\nport = split_address[1]<\/code><\/pre>\n<p>a serious Pythonista (<em>and<\/em> her dog) would instead say<\/p>\n<pre><code>host, port = address.split(':')<\/code><\/pre>\n<p>which is clearly superior on grounds of succinctness and beauty; we don't want our vision to be cluttered with this ugly sub-zero, sub-one notation when we can just declare a sequence of names.<\/p>\n<p>Consider, however, the somewhat-uncommon case where we have an iterable that, for whatever reason, we happen to <em>know<\/em> contains only one element, and we want to assign that one element to a variable. Here, I've seen people who ought to know better fall back to indexing:<\/p>\n<pre><code>if len(jobs) == 1:\r\n   job = jobs[0]<\/code><\/pre>\n<p>But there's <em>no reason<\/em> to violate the \u00e6sthetic principle of &quot;use a length-<em>n<\/em> (<a href=\"https:\/\/www.python.org\/dev\/peps\/pep-3132\/\">or smaller<\/a>) tuple of identifiers on the left side of a destructuring assignment in order to name the elements of a length-<em>n<\/em> iterable&quot; just because <em>n<\/em> happens to be one:<\/p>\n<pre><code>if len(jobs) == 1:\r\n   job, = jobs<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Python has this elegant destructuring-assignment iterable-unpacking syntax that every serious Pythonista and her dog tends to use where\u00ebver possible. So where a novice might write split_address = address.split(':') host = split_address[0] port = split_address[1] a serious Pythonista (and her dog) &hellip; <a href=\"http:\/\/zackmdavis.net\/blog\/2016\/04\/subzero\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[21],"_links":{"self":[{"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/posts\/1833"}],"collection":[{"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/comments?post=1833"}],"version-history":[{"count":3,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/posts\/1833\/revisions"}],"predecessor-version":[{"id":1836,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/posts\/1833\/revisions\/1836"}],"wp:attachment":[{"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/media?parent=1833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/categories?post=1833"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zackmdavis.net\/blog\/wp-json\/wp\/v2\/tags?post=1833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}