Решение на Пет малки функции от Симона Найденова

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

Към профила на Симона Найденова

Резултати

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

Код

def reps(someList):
newList=[]
for eachElement in someList:
if someList.count(eachElement) > 1:
newList.append(eachElement)
return tuple(newList)
def extract_type(someList,someType):
theResult = ""
for (element,number) in someList:
if type(element) == someType:
theResult += number * str(element)
return theResult
def reversed_dict(someDict):
reverseDict = {}
for country,capital in someDict.items():
reverseDict[capital] = country
return reverseDict
def flatten_dict(someDict):
flattenDict = {}
tempkey = ""
def check_fdict(someDict):
nonlocal tempkey
nonlocal flattenDict
for key,value in someDict.items():
if type(value) != type({}):
if tempkey == None:
flattenDict[key] = value
else:
flattenDict[tempkey + key] = value
elif type(value) == type({}):
tempkey = key + '.'
check_fdict(someDict[key])
check_fdict(someDict)
return flattenDict

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

...................
----------------------------------------------------------------------
Ran 19 tests in 0.168s

OK

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

Симона обнови решението на 23.03.2015 09:29 (преди над 9 години)

+def reps(someList):
+ newList=[]
+ for eachElement in someList:
+ if someList.count(eachElement) > 1:
+ newList.append(eachElement)
+ return tuple(newList)
+
+def extract_type(someList,someType):
+ theResult = ""
+ for (element,number) in someList:
+ if type(element) == someType:
+ theResult += number * str(element)
+ return theResult
+
+
+def reversed_dict(someDict):
+ reverseDict = {}
+ for country,capital in someDict.items():
+ reverseDict[capital] = country
+ return reverseDict
+
+def flatten_dict(someDict):
+ flattenDict = {}
+ tempkey = ""
+ def check_fdict(someDict):
+ nonlocal tempkey
+ nonlocal flattenDict
+ for key,value in someDict.items():
+ if type(value) != type({}):
+ if tempkey == None:
+ flattenDict[key] = value
+ else:
+ flattenDict[tempkey + key] = value
+ elif type(value) == type({}):
+ tempkey = key + '.'
+ check_fdict(someDict[key])
+
+ check_fdict(someDict)
+ return flattenDict