How to use Python's left outer join using FOR / LIST / DICTIONARY (not SQL) concepts?

I have two tuples, details below:

t1 = [ ['aa'], ['ff'], ['er'] ] 

 t2 = [ ['aa', 11,], ['er', 99,] ] 

and I would like to get results like the ones below using a python method similar to SQL LEFT OUTER JOIN:

 res = [ ['aa', 11,], ['ff', 0,], ['er', 99,] ] 

Please help me with this.

+4
source share
1 answer
 d2 = dict(t2) res = [[k[0], d2.get(k[0], 0)] for k in t1] 
+8
source

All Articles