Иванна обнови решението на 23.03.2015 12:07 (преди над 9 години)
+def extract_type2(text, typ):
+ new_list_tuples = [tup for tup in text if isinstance(tup[0], str)]
+ new_string = []
+ for tup in new_list_tuples:
+ new_string.append(tup[1]*tup[0])
+ result = ''.join(new_string)
+ return result
+
+def reversed_dict(my_dict):
+ new_dict = dict([(my_dict[key], key) for key in my_dict.keys()])
+ return new_dict
+
+def flatten_dict(my_dict):
+ def flatten(my_dict, result={}, prv_keys=[]):
+
+ for k, v in zip(my_dict.keys(), my_dict.values()):
+ if isinstance(v, dict):
+ flatten(v, result, prv_keys + [k])
+ else:
+ result['.'.join(prv_keys + [k])] = v
+
+ return result
+ print (flatten(my_dict, result={}, prv_keys=[]))
+
+def unflatten_dict(my_dict):
+ resultDict = dict()
+ for key, value in zip(my_dict.keys(), my_dict.values()):
+ 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
+ print (resultDict)
+
+def reps(my_list):
+ new_list = [x for x in my_list if my_list.count(x) > 1]
+ print (new_list)
Пусни си примерните тестове и махни print
-овете. Не винаги връщаш резултат.