I want to print all permutations of length 1-4 for the following list [1,2,3,4]
I know I could just set up a for-loop and pass in the for-loop index as an argument, but I was trying to get the following code to work:
import itertools
nums = [1,2,3,4]
perms = itertools.permutations(nums,range(1,4))
print(list(perms))
The hope was that the argument range(1,4)
would run the intertools.permutations(nums) on string lengths 1, 2, 3 and 4.
Any ideas if it is possible to do this using the itertools notation?
Would it also be possible to print the case for length = 1 as:
(1), (2), (3), (4)
not
(1,), (2,), (3,), (4,)