Dictionary merger. Input represents the two dictionaries dictionary, outputs the combined string, a dictionary of keys indicated by letter or number. Note: 1 and a '1' is different keywords!
Input formats:
Enter the first string dictionary in the first row in the input string of the second dictionary second row
Output formats:
The combined output of the dictionary in a row, the output lexicographical ordering. The ASCII "1" do 49, is greater than 1, when the previous sort 1, "1", the other is the same.
Sample Input 1:
Here we are given a set of inputs. E.g:
{1:3,2:5}
{1:5,3:7}
Output Sample 1:
Given here corresponding output. E.g:
{1:8,2:5,3:7}
Sample Input 2:
Here we are given a set of inputs. E.g:
{"1":3,1:4}
{"a":5,"1":6}
Output Sample 2:
Given here corresponding output. E.g:
{1:4,"1":9,"a":5}
d1=eval(input());d2=eval(input()) l1 = []; l2 = [] pl={} for i in d1: pl[i]=pl.get(i,0)+d1.get(i,0) if type(i)==type(1): l1.append(i) elif type(i)==type('w'): l2.append(i) for i in d2: pl[i] = pl.get(i, 0) + d2.get(i, 0) if type(i)==type(1): l1.append(i) elif type(i)==type('w'): l2.append(i) l1.sort();l2.sort() list=l1+l2 print("{",end="") cnt=0;length=len(pl) for i in list: if i in pl: cnt += 1 if type(i)==type(1): print("{}:{}".format(i,pl[i]),end="") else: print('"{}":{}'.format(i,pl[i]),end="") del pl[i] if cnt!=length: print(",",end="") print("}")