Feed on

use the itertools and random modules in python to get N pairwise combinations of a list’s items:

combo_it = itertools.combinations(my_list,2)
combo_l = list(combo_it)
pair_l = combo_l[:N]

Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

Did I get this wrong? Let me know!

Trackback URI | Comments RSS