import random
words = {'вперед', 'назад', 'вверх', 'вниз'}
a = None
for _ in range(15):
a = random.choice(tuple(words - {a}))
print(a)
import random
for _ in range(15): print(a := random.choice(tuple({'вперед', 'назад', 'вверх', 'вниз'} - {locals().get('a')})))
>> s = 'string'
>> w = Proxy(s)
>> isinstance(w, str), id(w)
True, 1680141601288
>> print(w)
string
>> w.__wrapped__ = [1, 2, 3]
>> isinstance(w, list), id(w)
True, 1680141601288
>> print(w)
[1, 2, 3]
@singledispatch
def get(date):
"""main docstring"""
print('main')
@get.register(datetime.date)
def _get_str(s):
"""str docstring"""
print('date')
get.__doc__ = '\n'.join([
get.__doc__,
f'\b\b{get.__name__}{inspect.signature(_get_str)}',
_get_str.__doc__,
])
from functools import singledispatch
class Test:
def __init__(self):
self.render = singledispatch(self.render)
self.render.register(str, self._render_str)
self.render.register(int, self._render_int)
def render(self, s):
raise TypeError(f"{type(s)} type isn't supported:")
def _render_str(self, s, b=None):
print("render str")
def _render_int(self, s):
print("render int")
t = Test()
>> t.render('s')
render str
>> t.render(1)
render int