-3
stock = {'football': 4, 'boardgame': 10, 'leggos': 100, 'doll': 5}    
def fillable(stock, merch, n):
      return stock.get(merch, 0) >= n

print(fillable(stock, 'leggos', 10))

The result in codewars:

Traceback: in in fillable TypeError: unorderable types: NoneType() >= int()

Alaskaboi
  • 37
  • 7
  • 5
    Presumably `merch` is a `dict` so it's calling `.get` and passing a default value if the key doesn't exist but who knows because you posted an incomplete example – EdChum Jan 05 '18 at 13:29
  • 1
    Allow me to answer with a question: what does `stock`'s `get` method do? – Jean-François Corbett Jan 05 '18 at 13:30
  • The code you've shown us is probably fine. Somehow `stock[merch]` is `None`. Inspect places where values are inserted, e.g. `stock[merch] = x` (where `x` may turn out to have the value `None`). – Alex Hall Jan 05 '18 at 13:36
  • It looks like `stock` is supposed to be a dictionary containing only integer values, but someone stored `None` at key `merch`. `stock.get(merch, 0)` would return zero when key `merch` is missing, but it won't protect you against bad data in the dictionary. – Steven Rumbalski Jan 05 '18 at 13:36
  • The code you've given works fine. Presumably codewars calls `fillable` with its own `stock` value that contains `None`. Include the question definition here. – Alex Hall Jan 05 '18 at 13:39

2 Answers2

0

Assuming n is int() in this case, try converting stock.get(merch, 0) to int before comparing it.

To answer your question: https://stackoverflow.com/a/2068377/2774199

SammyC
  • 1
  • 2
  • This likely won't work. The OP somehow has `None` stored against one of their keys (unlike in the sample given) and trying to cast that to not will throw an error. – roganjosh Jan 05 '18 at 14:07
0

Following is the syntax for get() method −

dict.get(key, default = None)
Parameters

key − This is the Key to be searched in the dictionary.

default − This is the Value to be returned in case key does not exist.

see more here.

keramat
  • 4,328
  • 6
  • 25
  • 38