删除特定的字符串python

时间:2018-01-03 03:55:05

标签: python numpy

我在python 3 numpy.ndarray中有以下内容:

{"_id" : "123", "text" : "some writing"}
{"_id" : "456", "text" : "some more writing"}
{"_id" : "789", "text" : "some more more writing"}

问题: 如何删除{"_id" :"text" :以获取以下内容:

{"123", "some writing"}
{"456", "some more writing"}
{"789", "some more more writing"}

1 个答案:

答案 0 :(得分:2)

以下是:

arr = [{"_id" : "123", "text" : "some writing"}, {"_id" : "456", "text" : "some more writing"}, {"_id" : "789", "text" : "some more more writing"}]
ans = [{i['_id']: i['text']}for i in arr]