title: TypeError: unorderable types: int() > NoneType()
body: <p>The algorithm problem <a href="https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/" rel="nofollow">No.188: Best Time to Buy and Sell Stock IV</a>. </p>
  
  <p><em>Say you have an array for which the ith element is the price of a given stock on day i.</em></p>
  
  <p><em>Design an algorithm to find the maximum profit. You may complete at most k transactions.</em></p>
  
  <p><em>Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).</em></p>
  
  <hr>
  
  <p>The following code is the solution: </p>
  
  <pre><code>#!/usr/bin/python
  
  class Solution:
      # @param {integer} k
      # @param {integer[]} prices
      # @return {integer}
      def maxProfit(self, k, prices):
          size = len(prices)
          if k &gt;= size/2:
              return self.quickSolve(size, prices)
          profit = [ None ]*(2*k+1)
          profit[0] = 0
          for i in range(size):
              for j in range(min(2*k, i+1), 0, -1):
                  profit[j] = max(profit[j], profit[j-1]+prices[i]*[1, -1][j%2]) 
          return max(profit)
      def quickSolve(self, size, prices):
          sum = 0
          for x in range(size-1):
              if prices[x+1] &gt; prices[x]:
                  sum += prices[x+1]-prices[x]
          return sum
  </code></pre>
  
  <p>This solution is working fine if I submit it on the Leetcode.   </p>
  
  <p>However, in my terminal, it gives the following error:</p>
  
  <pre><code> File "best_time_to_buy_and_sell_stock_IV.py", line 26, in maxProfit
      profit[j] = max(profit[j], profit[j-1]+prices[i]*[1, -1][j%2]) 
  TypeError: unorderable types: int() &gt; NoneType() 
  </code></pre>
  
  <p>This may because I am using <strong>python3</strong> and <strong><em>None</em></strong> cannot be compared with <strong><em>int</em></strong>, whereas <strong><em>profit</em></strong> is initialized as <strong><em>None</em></strong>.</p>
  
  <p>But why it is working on Leetcode test?   And how can I make it work under python3?     </p>
  
  <p>Thanks~ </p>