In python, I have tested combinations with a fixed length, with and without repetition by using multiple for loops. For example if I wanted to test every combination of numbers up to 5 with a length of 2 and repetition allowed, I would do this:
list1=[1,2,3,4,5]
for a in list1:
for b in list1:
print(str(a)+','+str(b) )
This seems simple enough for a fixed length but it does not work so well with testing all different lengths. When the length is varying, using this strategy I would have to make 5 different sets of 1, 2, 3, 4 and 5 loops. This is already very verbose and ugly but as the list size gets larger, it gets exponentially worse. I am looking for a more eloquent and easy way to test all of these combinations in python.