-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
33 lines (26 loc) · 1.08 KB
/
dictionary.py
File metadata and controls
33 lines (26 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
##############################################################################
# The program do not nothing special, only shows formatting dictionary
##############################################################################
A = {1: "one", 2: "two"}
B = {2: "dva", 3: "three"}
def transforms(A): # converts dict to list in tuple
l = []
for i in A.items():
l.append(i)
print("Converting dictionary:\n{}\n\nTo tuple:\n{}\n{}\n".format(A,
l,
"=" * 50))
def merge(A, B):
ax = A.copy()
bx = B.copy()
for key, value in bx.items():
if key in ax:
ax[key] = [ax[key], value]
else:
ax[key] = value
print(">>> A = {}\n>>> B = {}\n>>> Merge: {}\n{}\n".format(A,
B,
ax,
"=" * 50))
transforms(A)
merge(A, B)