Симона обнови решението на 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
Пусни си примерните тестове
Здравей, пуснах си примерните тестове и ми гърмят 3-та и 4-та функция. Flatten dict не ми работи като хората и нз защо, а Unlfatten dict не съм я правила въобще.