Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
class StrLink(str): def __new__(cls, content, parent, name, **kwargs): return str.__new__(cls, content, **kwargs) def __init__(self, content, parent, name, **kwargs): str.__init__(content) self.parent = parent self.name = name def update(self, new): setattr(self.parent, self.name, new) class TMP: def __init__(self): self.first_name = StrLink('Попов', parent=self, name='first_name') print() def set_info_to_atr(cls_atr, info): cls_atr.update(info) t = TMP() print(t.first_name) set_info_to_atr(t.first_name, 'Иван') print(t.first_name)
from itertools import chain, permutations s = [21, 234, 32] def all_subset(ss): return chain(*map(lambda x: permutations(ss, x), range(1, len(ss) + 1))) print( max( filter( lambda x: not x % 2, map( int, map( lambda v: ''.join(map(str, v)), all_subset(s) ) ) ) ) )
# Создает словарь, в котором перемешаеются ключи { 'a': 1, 'b': 2, 'c': 3, } from collections import OrderedDict print(OrderedDict(a=1, b=2, c=3)) print(OrderedDict((('a', 1), ('b', 2), ('c', 3))))
from collections import OrderedDict