I'm looking for a way to find all binary permutations with x amount of '1'. For example:
(length = 2) x = 1 (so: find all permutations of 1 and 0 with the length 2 which have one 1 in them)
l = ['01', '10']
x = 2 (so: find all permutations of 1 and 0 with the length 2 which have two 1 in them)
l = ['11']
so far i have this which calculates all possible permutations but i'm not sure how to 'filter' them by the '1's (especially when the size is 7 for example)
pre = list(map(''.join, itertools.product('01',repeat=2)))
i'm looking for something faster/better than my for loop which counts '1'.