Suppose I have two lists:
l1 = [['b', (1, 1)], ['b', (1, 2)], ['b', (1, 3)], ['a', (1, 5)], ['b', (2, 1)], ['b',(3, 1)]] l2 = ['A','B','C']
How can I create a dictionary in this format?
dct = {'A': len(sublist1), 'B': len(sublist2), 'C' : len(sublist3)}
Where
sublist1 = [['b', (1, 1)], ['b', (1, 2)], ['b', (1, 3)], ['a', (1, 5)]] sublist2 = [['b', (2, 1)]] sublist3 = [['b',(3, 1)]]
what happens if my l1 is given below:
ls1 = [[(1, 1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2)]]
then my conclusion should be:
dct = {'A': len(sublist1), 'B': len(sublist2)}
Where
sublist1 = [[(1, 1),(1, 2),(1, 3),(1, 4)]] sublist2 = [[(2, 1),(2, 2),(2, 3)]]
Is it possible to solve a general problem in a general way?