nums = [4,3,2,7,8,2,3,1]

for i in range(len(nums)):
    while nums[i] != i + 1 and nums[i] != nums[nums[i] - 1]:
        print("1: ", nums[i])
        print("2: ", nums[nums[i] - 1])
        # t = nums[i]
        # nums[i] = nums[nums[i-1]]
        # nums[nums[i-1]] = t
        nums[i], nums[nums[i] - 1] = nums[nums[i] - 1], nums[i]
        print("changed: ", nums[i])
        print("changed: ", nums[nums[i-1]])
        print(nums)
        
# res = []
# for j in range(len(nums)):
#     if nums[i] != i + 1:
#         res.append(i+1)
        
# print(res)