Вера обнови решението на 23.03.2015 08:09 (преди над 9 години)
+def extract_type(data):
+ return [x[0]*x[1] for x in data[0:-1] if type(x[0]) is data[-1]]
+
+
+def reversed_dict(destinations):
+ return {destinations[country]: country for country in destinations.keys()}
+print(reversed_dict({
+ "Israel": "Jerusalem",
+ "Austria": "Vienna",
+ "Palestine": "Jerusalem",
+ "Sweden": "Stockholm"}))
+
+
+def reps(numbers):
+ return [number for number in numbers
+ if numbers.count(number) is not 1]
+print(reps([1, 4, 2, 6, 7, 2, 4, 11, 1, 9, 0, 2, 5, 3, 1]))
+
+
+def flatten_dict(data):
+ result = {}
+
+ def helper(unflattened, last_key):
+ for element in unflattened.keys():
+ if type(unflattened[element]) is dict:
+ last_key_temp = last_key + element + '.'
+ helper(unflattened[element], last_key_temp)
+ else:
+ result[last_key + element] = unflattened[element]
+
+ helper(data, '')
+ return result
+
+
+def unflatten_dict(data):
+ def helper(key, count):
+ if '.' in key[count:]:
+ count += 2
+ return {key[count]: helper(key, count)}
+ else:
+ return data[key]
+
+ return {key[0]: helper(key, 0) for key in data.keys()}
Пусни си примерните тестове