Python Dictionary contains List as Value - How to update?

前端 未结 6 1496
甜味超标
甜味超标 2020-12-24 06:02

I have a dictionary which has value as a list.

dictionary = { 
               \'C1\' : [10,20,30] 
               \'C2\' : [20,30,40]
             }
<         


        
6条回答
  •  时光取名叫无心
    2020-12-24 06:12

    >>> dictionary = {'C1' : [10,20,30],'C2' : [20,30,40]}
    >>> dictionary['C1'] = [x+1 for x in dictionary['C1']]
    >>> dictionary
    {'C2': [20, 30, 40], 'C1': [11, 21, 31]}
    

提交回复
热议问题