Comparing The Solutions

  • First solution:

    d = {}
    for i in X + Y:
       d[i] = 1
    Z = d.keys()
    
  • Second solution:

    Z = dict([(t, 1) for t in X + Y]).keys()
    

Timing tests show that the second solution is between 2 to 3 times slower than the first solution for lists of between a hundred and a few tens of thousands of elements.