from collections import defaultdict

def hashJoin(table1, index1, table2, index2):
    h = defaultdict(list)
    
    for s in table1:
        h[s[index1]].append(s)
    
    return [(s, r) for r in table2 for s in h[r[index2]]]

table1 = [(27, ),
          (18, ),
          (28, ),
          (18, ),
          (28, )]
table2 = [(, ),
          (, ),
          (, ),
          (, ),
          (, )]

for row in hashJoin(table1, 1, table2, 0):
    print(row)