OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

After finding all combinations of 5 unique elements, I then want to find which combination appears the most times in a list of lists?

  • Thread starter Thread starter joelion2
  • Start date Start date
J

joelion2

Guest
In python I used itertools combination to get all unique 5 combinations:

Code:
from itertools import combinations
lst = ["a", "b", "c", "d","e"]
combinations_of_5 = list(combinations(lst, 5))

I then have a list of lists that I've filtered to only include items from lst. I now need to count the most popular combination found in a list of lists.

Code:
lst_of_lsts = [
               ["e", "d", "c", "b", "a", "c", "d", "b"],
               ["e", "b", "c", "a", "b", "e", "c"],
               ["a", "b", "a", "d", "b", "a", "a"],
               ["a", "b", "c", "d", "e", "c", "d"],
               ["e", "d", "c", "b","a"]
              ]

I thought it would be fairly straight forwards but I've been struggling to find a reliable way to do this and ensure the results are accurate. My actual list of lists is much larger (a few million lists) and I'd like to know the top 10 most popular combinations found in the list of lists. My thought was to maybe use a sliding window technique and see if any of the combinations exist in there.

any help appreciated.
<p>In python I used itertools combination to get all unique 5 combinations:</p>
<pre><code>from itertools import combinations
lst = ["a", "b", "c", "d","e"]
combinations_of_5 = list(combinations(lst, 5))
</code></pre>
<p>I then have a list of lists that I've filtered to only include items from lst. I now need to count the most popular combination found in a list of lists.</p>
<pre><code>lst_of_lsts = [
["e", "d", "c", "b", "a", "c", "d", "b"],
["e", "b", "c", "a", "b", "e", "c"],
["a", "b", "a", "d", "b", "a", "a"],
["a", "b", "c", "d", "e", "c", "d"],
["e", "d", "c", "b","a"]
]
</code></pre>
<p>I thought it would be fairly straight forwards but I've been struggling to find a reliable way to do this and ensure the results are accurate. My actual list of lists is much larger (a few million lists) and I'd like to know the top 10 most popular combinations found in the list of lists. My thought was to maybe use a sliding window technique and see if any of the combinations exist in there.</p>
<p>any help appreciated.</p>
 

Latest posts

Online statistics

Members online
0
Guests online
5
Total visitors
5
Ads by Eonads
Top