Getting a list of values from a list of dicts

前端 未结 9 734
执念已碎
执念已碎 2020-11-22 15:22

I have a list of dicts like this:

[{\'value\': \'apple\', \'blah\': 2}, 
 {\'value\': \'banana\', \'blah\': 3} , 
 {\'value\': \'cars\', \'blah\': 4}]
         


        
9条回答
  •  无人共我
    2020-11-22 15:24

    A very simple way to do it is:

    list1=['']
    j=0
    for i in com_list:
        if j==0:
            list1[0]=(i['value'])
        else:
            list1.append(i['value'])
        j+=1
    

    Output:

    ['apple', 'banana', 'cars']

提交回复
热议问题