Решение на Пет малки функции от Гюлджан Купен

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

Към профила на Гюлджан Купен

Резултати

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

Код

def extract_type(items, filter_type):
return ''.join([str(item[0]) * item[1] for item in items
if type(item[0]) is filter_type])
def reversed_dict(items):
return {value: key for key, value in items.items()}
def flatten_dict(items, parent_key=''):
result = []
for key, value in items.items():
if parent_key:
new_key = parent_key + '.' + key
else:
new_key = key
if isinstance(value, dict):
result.extend(flatten_dict(value, new_key).items())
else:
result.append((new_key, value))
return dict(result)
def unflatten_dict(items):
result = {}
for key, value in items.items():
context = result
for sub_key in key.split('.')[:-1]:
if sub_key not in context:
context[sub_key] = {}
context = context[sub_key]
context[key.split('.')[-1]] = value
return result
def reps(items):
return tuple([item for item in items if items.count(item) != 1])

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

...................
----------------------------------------------------------------------
Ran 19 tests in 0.159s

OK

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

Гюлджан обнови решението на 18.03.2015 00:33 (преди над 9 години)

+def extract_type(d, t):
+ result = ''
+ for item in d:
+ if isinstance(item[0], t):
+ result += str(item[0]) * item[1]
+ return result
+
+
+def reversed_dict(d):
+ result = []
+ for k, v in d.items():
+ result.append((v, k))
+ return dict(result)
+
+
+def flatten_dict(d, parent_key=''):
+ result = []
+ for k, v in d.items():
+ if parent_key:
+ new_key = parent_key + '.' + k
+ else:
+ new_key = k
+ if isinstance(v, dict):
+ result.extend(flatten_dict(v, new_key).items())
+ else:
+ result.append((new_key, v))
+ return dict(result)
+
+
+def unflatten_dict(d):
+ result = {}
+ for k, v in d.items():
+ context = result
+ for sub_key in k.split('.')[:-1]:
+ if sub_key not in context:
+ context[sub_key] = {}
+ context = context[sub_key]
+ context[k.split('.')[-1]] = v
+ return result
+
+
+def reps(d):
+ result = []
+ for item in d:
+ index = d.index(item)
+ if (item in d[index + 1:-1] or
+ item in d[0:index] or
+ item == d[-1]):
+ result.append(item)
+ return tuple(result)

Гюлджан обнови решението на 18.03.2015 22:28 (преди над 9 години)

def extract_type(d, t):
result = ''
for item in d:
- if isinstance(item[0], t):
+ if type(item[0]) is t:
result += str(item[0]) * item[1]
return result
def reversed_dict(d):
result = []
- for k, v in d.items():
- result.append((v, k))
+ for key, value in d.items():
+ result.append((value, key))
return dict(result)
def flatten_dict(d, parent_key=''):
result = []
- for k, v in d.items():
+ for key, value in d.items():
if parent_key:
- new_key = parent_key + '.' + k
+ new_key = parent_key + '.' + key
else:
- new_key = k
- if isinstance(v, dict):
- result.extend(flatten_dict(v, new_key).items())
+ new_key = key
+ if isinstance(value, dict):
+ result.extend(flatten_dict(value, new_key).items())
else:
- result.append((new_key, v))
+ result.append((new_key, value))
return dict(result)
def unflatten_dict(d):
result = {}
- for k, v in d.items():
+ for key, value in d.items():
context = result
- for sub_key in k.split('.')[:-1]:
+ for sub_key in key.split('.')[:-1]:
if sub_key not in context:
context[sub_key] = {}
context = context[sub_key]
- context[k.split('.')[-1]] = v
+ context[key.split('.')[-1]] = value
return result
def reps(d):
result = []
for item in d:
- index = d.index(item)
- if (item in d[index + 1:-1] or
- item in d[0:index] or
- item == d[-1]):
+ if d.count(item) != 1:
result.append(item)
return tuple(result)

Гюлджан обнови решението на 20.03.2015 22:41 (преди над 9 години)

def extract_type(d, t):
result = ''
for item in d:
if type(item[0]) is t:
result += str(item[0]) * item[1]
return result
def reversed_dict(d):
- result = []
- for key, value in d.items():
- result.append((value, key))
- return dict(result)
+ return {value: key for key, value in d.items()}
def flatten_dict(d, parent_key=''):
result = []
for key, value in d.items():
if parent_key:
new_key = parent_key + '.' + key
else:
new_key = key
if isinstance(value, dict):
result.extend(flatten_dict(value, new_key).items())
else:
result.append((new_key, value))
return dict(result)
def unflatten_dict(d):
result = {}
for key, value in d.items():
context = result
for sub_key in key.split('.')[:-1]:
if sub_key not in context:
context[sub_key] = {}
context = context[sub_key]
context[key.split('.')[-1]] = value
return result
def reps(d):
- result = []
- for item in d:
+ return tuple([item for item in d if d.count(item) != 1])
- if d.count(item) != 1:
- result.append(item)
- return tuple(result)

Гюлджан обнови решението на 21.03.2015 20:54 (преди над 9 години)

-def extract_type(d, t):
- result = ''
- for item in d:
- if type(item[0]) is t:
- result += str(item[0]) * item[1]
- return result
+def extract_type(sequence, filter_type):
+ return ''.join([str(item[0]) * item[1] for item in sequence
+ if type(item[0]) is filter_type])
-def reversed_dict(d):
- return {value: key for key, value in d.items()}
+def reversed_dict(sequence):
+ return {value: key for key, value in sequence.items()}
-def flatten_dict(d, parent_key=''):
+def flatten_dict(sequence, parent_key=''):
result = []
- for key, value in d.items():
+ for key, value in sequence.items():
if parent_key:
new_key = parent_key + '.' + key
else:
new_key = key
if isinstance(value, dict):
result.extend(flatten_dict(value, new_key).items())
else:
result.append((new_key, value))
return dict(result)
-def unflatten_dict(d):
+def unflatten_dict(sequence):
result = {}
- for key, value in d.items():
+ for key, value in sequence.items():
context = result
for sub_key in key.split('.')[:-1]:
if sub_key not in context:
context[sub_key] = {}
context = context[sub_key]
context[key.split('.')[-1]] = value
return result
-def reps(d):
- return tuple([item for item in d if d.count(item) != 1])
+def reps(sequence):
+ return tuple([item for item in sequence if sequence.count(item) != 1])

Гюлджан обнови решението на 22.03.2015 23:20 (преди над 9 години)

-def extract_type(sequence, filter_type):
- return ''.join([str(item[0]) * item[1] for item in sequence
+def extract_type(items, filter_type):
+ return ''.join([str(item[0]) * item[1] for item in items
if type(item[0]) is filter_type])
-def reversed_dict(sequence):
- return {value: key for key, value in sequence.items()}
+def reversed_dict(items):
+ return {value: key for key, value in items.items()}
-def flatten_dict(sequence, parent_key=''):
+def flatten_dict(items, parent_key=''):
result = []
- for key, value in sequence.items():
+ for key, value in items.items():
if parent_key:
new_key = parent_key + '.' + key
else:
new_key = key
if isinstance(value, dict):
result.extend(flatten_dict(value, new_key).items())
else:
result.append((new_key, value))
return dict(result)
-def unflatten_dict(sequence):
+def unflatten_dict(items):
result = {}
- for key, value in sequence.items():
+ for key, value in items.items():
context = result
for sub_key in key.split('.')[:-1]:
if sub_key not in context:
context[sub_key] = {}
context = context[sub_key]
context[key.split('.')[-1]] = value
return result
-def reps(sequence):
- return tuple([item for item in sequence if sequence.count(item) != 1])
+def reps(items):
+ return tuple([item for item in items if items.count(item) != 1])