summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2019-03-13 20:25:30 +0400
committerAndrew <saintruler@gmail.com>2019-03-13 20:25:30 +0400
commit89d8d426f5024a82d793955952d65c0e36370e59 (patch)
tree9b815a88c477c0145150377734b1912a814faa46
parent93137896beb12fc8881979050d071ff2c3c02c47 (diff)
Четвертая задача второго дня
-rw-r--r--day2/task4/task4.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/day2/task4/task4.py b/day2/task4/task4.py
new file mode 100644
index 0000000..21d3767
--- /dev/null
+++ b/day2/task4/task4.py
@@ -0,0 +1,25 @@
+def print_dict(d: dict):
+ for key, val in d.items():
+ print(f'{key} = {val}')
+
+
+data = ''
+while not data:
+ data = input()
+
+d = {}
+pairs = data.split(';')
+for pair in pairs:
+ try:
+ key, val = pair.split('=')
+ except ValueError:
+ print(f'Неверный формат ввода -> "{pair}"')
+ quit()
+ else:
+ d[key.strip()] = val.strip()
+
+print_dict(d)
+print('#' * 40)
+
+inverted_dict = dict(zip(d.values(), d.keys()))
+print_dict(inverted_dict)