我需要访问列表中列表的元素。
我尝试了以下代码:
connections ={}
for i in connections_with_names:
connections['dog']=[dict1[i] for i in dict2[i] if i not in connections_with_names[0]['dog']]
但是我回来了:
KeyError: 0
此外,connections_with_names['dog']
如下所示:
[['furry',
'loud',
'shed']]
我需要for i in dict2[i] if i not in connections_with_names[0]['dog']]
才能访问3个元素(毛茸茸,吵闹,棚屋)并排除这些元素。我认为问题与connections_with_names[0]
部分有关,但不确定。