Станислав обнови решението на 23.03.2015 16:08 (преди над 9 години)
+from functools import reduce
+# import operator
+
+
+def extract_type(list_, type_):
+
+ extract = list(filter((lambda x: type(x[0]) == type_), list_))
+ extract = list(map((lambda x: str(x[0]) * x[1]), extract))
+ extract = reduce((lambda x, y: x + y), extract)
+ return extract
+
+
+def reversed_dict(dictionary):
+
+ reverse = {}
+ for key in dictionary:
+ reverse[dictionary[key]] = key
+ return reverse
+
+
+def flatten_dict(dictionary):
+
+ new_dic = {}
+
+ for x in dictionary:
+ if type(dictionary[x]) is type({}):
+ for y in dictionary[x]:
+ if type(dictionary[x][y]) is not type({}):
+ new_key = str(x + "." + y)
+ new_dic[new_key] = dictionary[x][y]
+ else:
+ for z in dictionary[x][y]:
+ new_key = str(x + "." + y + "." + z)
+ new_dic[new_key] = dictionary[x][y][z]
+ else:
+ new_dic[x] = dictionary[x]
+ return new_dic
+
+
+def unflatten_dict(dictionary):
+ # Грип ме тръшна, едвам направих другите :)
+ pass
+
+
+def reps(elements):
+
+ return tuple([item for item in elements if elements.count(item) > 1])
Какво се случва с extract_type
, ако му подадеш списък без елементи от търсения тип?