Jun-04-2020, 04:01 PM
The first two elements of the list you want aren't products at all, unless you extend the range of possibilities like
If you do that, then you could generate them and sort the result. But I'm not sure I understand exactly what list you want.
a = ['', 'a', 'b']
.If you do that, then you could generate them and sort the result. But I'm not sure I understand exactly what list you want.
>>> a = ['', 'a', 'b'] >>> b = ['', '1', '2'] >>> sorted(["".join(x) for x in product(a,b)], key=len) ['', '1', '2', 'a', 'b', 'a1', 'a2', 'b1', 'b2']