There is one question I am working on and got a very close answer… basically, the question is that you get two dictionaries and you have to find elements that intersect from both dictionaries and then create those elements (one same key from both dicts and two values from both dics) in a new dictionary.
a = {'A':17,'B':31,'C':42,'D':7,'E':46,'F':39,'G':9}
b = {'D':8,'E':3,'F':2,'g':5}
def intersect(a,b):
c = set(a).intersection(set(b))
d = {}
for i in c:
if i in a:
d[i] = int(a[i]),int(b[i])
return d
OUTPUT: {'E': (46, 3), 'D': (7, 8), 'F': (39, 2)}
I want to get the output like {‘E’: 46, 3, ‘D’: 7, 8, ‘F’: 39, 2}
How do I get rid of the parentheses around the values?
The code as you have written won’t output anything at all. However, if you want to remove parentheses, then you can use this.
or equivalently this, which is a bit more concise and efficient