Question: 
Write a function to assign with each element, its pair elements from other similar pairs in the given tuple.


Model's Code:
def assign_elements(pairs):
    mapping = {}
    for a, b in pairs:
        if a not in mapping:
            mapping[a] = []
        if b not in mapping:
            mapping[b] = []
        mapping[a].append(b)
    
    for key in mapping:
        mapping[key] = list(set(mapping[key]))  # Remove duplicates
    for a in pairs:
        if a[0] not in mapping:
            mapping[a[0]] = []
        if a[1] not in mapping:
            mapping[a[1]] = []
    
    return mapping



Sample Correct Code:
def assign_elements(test_list):
  res = dict()
  for key, val in test_list:
    res.setdefault(val, [])
    res.setdefault(key, []).append(val)
  return (res) 


Asserts:
assert assign_elements([(5, 3), (7, 5), (2, 7), (3, 8), (8, 4)] ) == {3: [8], 5: [3], 7: [5], 2: [7], 8: [4], 4: []}
assert assign_elements([(6, 4), (9, 4), (3, 8), (4, 9), (9, 5)] ) == {4: [9], 6: [4], 9: [4, 5], 8: [], 3: [8], 5: []}
assert assign_elements([(6, 2), (6, 8), (4, 9), (4, 9), (3, 7)] ) == {2: [], 6: [2, 8], 8: [], 9: [], 4: [9, 9], 7: [], 3: [7]}


Tests:
Test 1 of 3: PASS
Test 2 of 3: PASS
Test 3 of 3: FAIL: AssertionError()

Test 561 of 974: 415/561 (73.97504456327985%): failed