Getting 'int' object is not iterable

后端 未结 3 1362
日久生厌
日久生厌 2021-01-25 21:00
    cat_sums[cat] += value
TypeError: \'int\' object is not iterable

My input is this:

defaultdict(, {\'composed\'         


        
3条回答
  •  鱼传尺愫
    2021-01-25 21:18

    Each of your values is a list. The + operator, when applied to lists adds an iterable to a list. It doesn't append a single value:

    >>> [1,2] + [3,4]
    [1, 2, 3, 4]
    >>> [1,2] + 3
    TypeError: can only concatenate list (not "int") to list
    

    It looks like you want to do cat_sums[cat].append(value).

提交回复
热议问题