import re
def to_seconds(instr: str) -> int:
FORMAT = {
'\D?(\d+)s': lambda x: x,
'\D?(\d+)m': lambda x: 60 * x,
'\D?(\d+)h': lambda x: 60 * 60 * x,
'\D?(\d+)d': lambda x: 24 * 60 * 60 * x,
'\D?(\d+)w': lambda x: 7 * 24 * 60 * 60 * x,
}
outstr = 0
for key in FORMAT:
if re.search(key, instr):
outstr += FORMAT[key](int(re.search(key, instr).group(1)))
return outstr
str1 = "3w3d12h12m40s"
print(to_seconds(str1))
Two sets are equal if and only if every element of each set is contained in the other (each is a subset of the other). A set is less than another set if and only if the first set is a proper subset of the second set (is a subset, but is not equal). A set is greater than another set if and only if the first set is a proper superset of the second set (is a superset, but is not equal).
If multiple items are minimal, the function returns the first one encountered.
from django.core.cache import cache
IP_KEY = 'request_ban:{ip}'
DELAY = 3600
result = cache.get(IP_KEY.format(ip=ip))
if result:
difference = (result - datetime.datetime.now()).seconds
print(f'Вам осталось {difference} секунд')
else:
cache.set(
IP_KEY.format(ip=ip),
datetime.datetime.now() + datetime.timedelta(seconds=DELAY),
DELAY,
)
print('Добро пожаловать!')
try:
if {
'+': lambda o, t, h: o + t == h,
'-': lambda o, t, h: o - t == h,
'*': lambda o, t, h: o * t == h,
'/': lambda o, t, h: o / t == h,
}.get(j)(o, t, h):
print('YES')
else:
print('NO')
except KeyError:
print('Неизвестная функция')
except ZeroDivisionError:
print('Деление на ноль')