“TypeError: 'NoneType' object is not callable” when adding lists to dictionary

前端 未结 3 442
情深已故
情深已故 2021-01-23 20:28

I\'m creating a function that consolidates a couple of lists into a string and am encountering the below error.

Traceback (most recent call last):
  File \"Tradi         


        
3条回答
  •  甜味超标
    2021-01-23 20:55

    If you are using Python 2, then either map or dict is bound to None. Check the rest of your code for assignments to either name.

    Note that instead of map(None, iterable1, iterable2) you can use zip(iterable1, iterable2) to get the same output.

    If you are using Python 3, then the map() method does not support None as a first argument:

    >>> list(map(None, [1], [2]))
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: 'NoneType' object is not callable
    

    and you certainly want to use zip() there:

    defsTwo = dict(zip(letters, defsOne))
    

提交回复
热议问题