title: Simple Python code with weird list manipulation/comprehension technique by which one element of the list gets assigned to a variable
body: <p>Today I was browsing through a coding website and found a simple code in Python which I was having a hard time to comprehend.</p>
  <p>Below is the exact code (with extra details added as comments):</p>
  <pre><code>x = -23 
  
  sign = [1,-1][x &lt; 0] # -1 if x is negative and 1 if x is positive
  
  print(sign) #outputs -1 since x=-23 is negative
  </code></pre>
  <p>Can anyone please help me understand how this code is working and what this technique is called (I presume it is some kind of list comprehension/manipulation)?</p>