d=("adf": 1, "bdc":2,"cdsd":4)
def longest_key (d):
longest None
for key in d: if not longest or len (key) > len (longest):
longest = key
return longest
print(longest_key(d)).
When i do this the program is fine and no error occurs but
d=("adf": 1, "bdc":2,"cdsd":4) def longest_key (d):
longest = None
for key in d: if len (key) > len (longest):
longest key
return longest print (longest_key(d)).
When i do this it shows type error object of type Nonetype has no len()
You set
longestto None and you're trying to get its length. In the second function, it errors because you don't have theif not longestcondition. The first function works because short circuit evaluation means thatlen(longest)will not be evaluated.