从字符串json中创建一个列表?蟒蛇

时间:2016-10-08 16:37:04

标签: python

我有一个json字符串,我从json数组得到它,我已经给它了

annotation = sentence["annotation"]
text = sentence["text"]
#ioblist = [annotation]
ioblist=[[x[0], x[4]] for x in annotation]  #nothing

proram没有转换这里是我在索引0的列表中的字符串

   {u'1': [u'Bill', u'bill', u'NNP', u'B-PERSON'], 
   u'3': [u'born', u'bear', u'VBN', u'O'], 
   u'2': [u'was', u'be', u'VBD', u'O'], 
   u'5':  [u'.', u'.', u'.', u'O'], 
   u'4': [u'1986', u'BIL', u'CD', u'B-DATE']}

更新1:

我正在列表

 ioblist=[[x[0], x[4]] for x in annotation]

1 个答案:

答案 0 :(得分:0)

range()为您提供了一个可迭代的整数,但您的字典键是u'...',即unicode字符串。因此,查找ioblist[0]必须失败,因为0 != u'0'(谢天谢地,Python不是PHP)。