Blossoms


#1

So I am working on the Blossoms project in the computer science path. The instructions say:

If payload is not None , then we know it’s a list that looks like [key, value] .

Check the first item ( payload[0] ) and compare it with key . If they are the same, return the second item in payload (the value!).

If payload is None or the first item is not the same as key , return None .

So the code I wrote is: https://gist.github.com/357d0309183c75006b11e07a9ef7ee34

But when I watched the video to compare they had something slightly different. what they had is:

if payload != None
return payload[1]
else
return None

Is the code in the video not wrong since it don’t cover the case of the first item not being the same as the key?


#2

Hi @akeller33,

You have this …

   if payload[0] == key:
      return payload[1]
    return None

The problem is that if the payload is None and you try to check payload[0], you have attempted to subscript None, which is an error. You must first make sure payload is not equal to None before you attempt subscript it.