Apr-05-2023, 08:42 PM
my interpreation of this task:
from itertools import permutations res = [] nums = [1,2,3,4] not_allowed = [(1,2),(2,3),(3,4)] for perm in permutations(nums,2): if perm not in not_allowed: res.append(perm) print(res)
Output:[(1, 3), (1, 4), (2, 1), (2, 4), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)]