title: How to check if a given number is a power of two?
body: <p>The code below isn't working right for some inputs.</p>
  
  <pre class="lang-py prettyprint-override"><code>a, i = set(), 1
  while i &lt;= 10000:
      a.add(i)
      i &lt;&lt;= 1
  
  N = int(input())
  if N in a:
      print("True")
  else:
      print("False")
  </code></pre>
  
  <p>My initial idea was to check for each input if it's a power of 2 by starting from 1 and multiplying by 2 until exceeding the input number, comparing at each step. Instead, I store all the powers of 2 in a <code>set</code> beforehand, in order to check a given input in <code>O(1)</code>. How can this be improved?</p>