假设我有两个列表:
l1 = [['b', (1, 1)], ['b', (1, 2)], ['b', (1, 3)], ['a', (1, 5)],
['b', (2, 1)], ['b',(3, 1)]]
l2 = ['A','B','C']
如何创建这种格式的字典?
dct = {'A': len(sublist1), 'B': len(sublist2), 'C' : len(sublist3)}
在哪里
sublist1 = [['b', (1, 1)], ['b', (1, 2)], ['b', (1, 3)], ['a', (1, 5)]]
sublist2 = [['b', (2, 1)]]
sublist3 = [['b',(3, 1)]]
如果我的 l1 如下所示会发生什么:
ls1 = [[(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2)]]
那么我的输出应该是:
dct = {'A': len(sublist1), 'B': len(sublist2)}
在哪里
sublist1 = [[(1, 1),(1, 2),(1, 3),(1, 4)]]
sublist2 = [[(2, 1),(2, 2),(2, 3)]]
可以用通用的方式解决整体问题吗?