Решение на Пет малки функции от Мария Османлиева

Обратно към всички решения

Към профила на Мария Османлиева

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 19 успешни тест(а)
  • 0 неуспешни тест(а)

Код

def reversed_dict(names):
dict = {country: city for city, country in names.items()}
return dict
import collections
def flatten(el, parent_key='', sep='.'):
items = []
for k, v in el.items():
new_key = parent_key + sep + k if parent_key else k
if isinstance(v, collections.MutableMapping):
items.extend(flatten(v, new_key, sep=sep).items())
else:
items.append((new_key, v))
return dict(items)
def unflatten(dictionary):
resultDict = dict()
for key, value in dictionary.iteritems():
parts = key.split(".")
d = resultDict
for part in parts[:-1]:
if part not in d:
d[part] = dict()
d = d[part]
d[parts[-1]] = value
return resultDict
def reps(numbers):
eqq = []
for number in numbers:
if numbers.count(number) > 1:
eqq.append(number)
return eqq
def extract(list, my_type):
return ''.join([x*y for(x, y) in list if isinstance(x, my_type)])

Лог от изпълнението

...................
----------------------------------------------------------------------
Ran 19 tests in 0.166s

OK

История (1 версия и 1 коментар)

Мария обнови решението на 23.03.2015 14:51 (преди над 9 години)

+def reversed_dict(names):
+ dict = {country: city for city, country in names.items()}
+ return dict
+
+import collections
+
+
+def flatten(el, parent_key='', sep='.'):
+ items = []
+ for k, v in el.items():
+ new_key = parent_key + sep + k if parent_key else k
+ if isinstance(v, collections.MutableMapping):
+ items.extend(flatten(v, new_key, sep=sep).items())
+ else:
+ items.append((new_key, v))
+ return dict(items)
+
+
+def unflatten(dictionary):
+ resultDict = dict()
+ for key, value in dictionary.iteritems():
+ parts = key.split(".")
+ d = resultDict
+ for part in parts[:-1]:
+ if part not in d:
+ d[part] = dict()
+ d = d[part]
+ d[parts[-1]] = value
+ return resultDict
+
+
+def reps(numbers):
+ eqq = []
+ for number in numbers:
+ if numbers.count(number) > 1:
+ eqq.append(number)
+ return eqq
+
+
+def extract(list, my_type):
+ return ''.join([x*y for(x, y) in list if isinstance(x, my_type)])