HNHacker News
TopNewBestAskShowJobs

zebulanmcranahn

-1 karma · joined July 27, 2014

Novice Python Enthusiast.
submissionscomments
zebulanmcranahn··on Python Multiple Assignment Is a Puzzle
Thanks for the ValueError tip. I added it as well as a TypeError just in case the input comes in as a string. My skills are beginner level at best, tips like yours help a lot!
zebulanmcranahn··on Python Multiple Assignment Is a Puzzle

  def firstMissingPositive(A):
      try:
          for x in range(1, max(A)+1):
              if x not in A: return x
      except: return A

  def firstMissingPositive(A):
      try: return next(x for x in range(1, max(A)+1) if x not in A)
      except: return A
Two above return:

  print(firstMissingPositive([4,2,5,7,1])) # 3
  print(firstMissingPositive([4,100]))     # 1
  print(firstMissingPositive([]))          # []
  print(firstMissingPositive([5]))         # 1
I wasn't sure what [5] or [] were supposed to return so maybe I'm still wrong? Had never heard of this question before, thought I'd try it out.

Thanks for the reply, very informative.

zebulanmcranahn··on Python Multiple Assignment Is a Puzzle
def findMissingPositive(A): A.sort() return min([x for x in range(A[0], A[-1]+1) if x not in A])