just feed your list to itertools.permutations
and format accordingly in a list comprehension directly passing the tuple
to format
using the *
operator.
import itertools
result = ["{}-{}".format(*x) for x in itertools.permutations([3, 8, 2],2)]
print(result)
result:
['3-8', '3-2', '8-3', '8-2', '2-3', '2-8']
As a side note, don't use input
as a variable name as it overrides the interactive text input function.