There are several similar questions around that suggest using any()
with sets, however mine is a bit different in a way that I want to get the most effective and Pythonic way of forming a new array out of existing arrays based on membership.
I have the following array [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 4, 5, 6], [2, 4, 5, 6, 9, 1, 4, 5, 6, 4, 5, 6], [1, 2, 9, 4, 5, 6, 7, 7, 8, 5]]
What I need is a way to form a new object {[4, 5, 6] : 6}
where [4, 5, 6]
is the key, and 6
is the number of times the key sequence appears in the array above.
I have achieved the result by making a function with simple for loops, but I don't think it is the most Pythonic and efficient way of achieving it. I was thinking of using map()
and filter()
as well.
What would be the most efficient and Pythonic way of achieving the result?