I have this tuple of tuples;
Tup1= ( ('AAA', 2), ('BBB', 3) )
I have another tuple;
Tup2 = ('AAA', 'BBB', 'CCC', 'DDD')
I want to compare Tup1
and Tup2
. Based on the comparison, I want to create another tuple of tuples that look like this;
OutputTup = ( ('AAA', 2), ('BBB', 3), ('CCC', 0), ('DDD', 0) )
The logic is like this. Look into every element inside Tup2 and then look for matching element in Tup1. If there is matching element(example 'AAA') in Tup1, copy to OutputTup ('AAA', 2). If there is no matching element (example 'CCC'), then assign a value of 0 and append to OutputTup ('CCC', 0).
How can this be done in Python 2.7? Thanks.