【问题标题】:Convert list of dictionary into list [duplicate]将字典列表转换为列表[重复]
【发布时间】:2020-03-19 09:12:40
【问题描述】:

我有这样格式的数据:

[{"user": "fgb59h", "id": 4, "text": 'hello'},

{"user": "bucho_ky", "id": 20, "text": 'why'},

{"user": "redp944", "id": 40, "text": 'this is an example'},
]

我想选择“文本”并将其转换为:

 ['hello','why','this is an example']

这样我就可以对数据进行文本分析。

我应该怎么做?

提前致谢!!

【问题讨论】:

    标签: python list


    【解决方案1】:

    另一种可能性:

    DATA = [{"user": "fgb59h", "id": 4, "text": 'hello'},
    
    {"user": "bucho_ky", "id": 20, "text": 'why'},
    
    {"user": "redp944", "id": 40, "text": 'this is an example'},
    ]
    
    result = [i['text'] for i in DATA]
    print(result)
    

    【讨论】:

      猜你喜欢
      • 2019-11-27
      • 2016-08-29
      • 2020-11-11
      • 2011-10-17
      • 2017-10-01
      • 1970-01-01
      • 2018-02-08
      • 2019-11-18
      • 1970-01-01
      相关资源
      最近更新 更多