我有一个列表,其中每个列表是一个句子。我试图将这个列表转换成一个列表字典,每个单独的句子都有一个关键字。我的这种尝试为每个单词提供了一个关键字,而不是每个单独的句子。这是我的输入当前的样子。将列表的列表换行为列表的字典中断行
{1: '[[try', 2: 'not', 3: 'become', 4: 'man', 5: 'success', 6: 'but', 7:
'rather', 8: 'try', 9: 'become', 10: 'man', 11: 'value]', 12: '[look', 13:
'deep', 14: 'into', 15: 'nature', 16: 'and', 17: 'then', 18: 'you', 19:
'will', 20: 'understand', 21: 'everything', 22: 'better]', 23: '[the', 24:
'true', 25: 'sign', 26: 'intelligence', 27: 'not', 28: 'knowledge', 29:
'but', 30: 'imagination]', 31: '[we', 32: 'cannot', 33: 'solve', 34: 'our',
35: 'problems', 36: 'with', 37: 'the', 38: 'same', 39: 'thinking', 40:
'used', 41: 'when', 42: 'created', 43: 'them]', 44: '[weakness', 45:
'attitude', 46: 'becomes', 47: 'weakness', 48: 'character]', 49: '["you',
50: 'cant', 51: 'blame', 52: 'gravity', 53: 'for', 54: 'falling', 55:
'love"]', 56: '[the', 57: 'difference', 58: 'between', 59: 'stupidity', 60:
'and', 61: 'genius', 62: 'that', 63: 'genius', 64: 'has', 65: 'its', 66:
'limits]]'}
我想这个代替:提前
{1:'[[try', 'not', 'become', 'man', 'success', 'but', 'rather', 'try',
'become', 'man', 'value]', 2: '[look', 'deep', 'into', 'nature', 'and',
'then', 'you', 'will', 'understand', 'everything', 'better]', 3:'[the',
'true', 'sign', 'intelligence', 'not', 'knowledge', 'but', 'imagination]',
4:'[we', 'cannot', 'solve', 'our', 'problems', 'with', 'the', 'same',
'thinking', 'used', 'when', 'created', 'them]', 5: '[weakness', 'attitude',
'becomes', 'weakness', 'character]', 6:'["you', 'cant', 'blame', 'gravity',
'for', 'falling', 'love"]', '7: [the', 'difference', 'between', 'stupidity',
'and', 'genius', 'that', 'genius', 'has', 'its', 'limits]]'}
谢谢!
我的列表清单如下:
['[[try', 'not', 'become', 'man', 'success', 'but', 'rather', 'try',
'become', 'man', 'value]', '[look', 'deep', 'into', 'nature', 'and',
'then', 'you', 'will', 'understand', 'everything', 'better]', '[the',
'true', 'sign', 'intelligence', 'not', 'knowledge', 'but', 'imagination]',
'[we', 'cannot', 'solve', 'our', 'problems', 'with', 'the', 'same',
'thinking', 'used', 'when', 'created', 'them]', '[weakness', 'attitude',
'becomes', 'weakness', 'character]', '["you', 'cant', 'blame', 'gravity',
'for', 'falling', 'love"]', '[the', 'difference', 'between', 'stupidity',
'and', 'genius', 'that', 'genius', 'has', 'its', 'limits]]']
我认为你想要的输出是不正确的......除非我完全误解。你想要一个键(整数)映射到一个标记列表(而不是你显示的字符串)?即,'{1:['try',...,'value'],2:['look',...]}'或者那是错的? – Tgsmith61591