У меня есть своя функция для округления чисел... В строках для форматирования функции не работают
balance = 1.237
s = f"Balance: {my_round(balance)}"
print(s)
from binascii import hexlify
url = "..."
querystring = {..., ...,}
headers = {...}
content = querystring['content'].encode('utf-16-be')
querystring['content'] = hexlify(content).decode('utf-8')
responce = request.....
from binascii import hexlify
querystring = {'content': 'Привет'}
content = querystring['content'].encode('utf-16-be')
querystring['content'] = hexlify(content).decode('utf-8')
print(querystring)
In [4]:
{'content': '041f04400438043204350442'}
x = [0.0799, 0.07991, 0.07998, 0.08, 0.080574, 0.081, 0.082, 0.08405, 0.085]
raznica = (0.00001, 0.00009, 0.00405)
prev = x[0]
new_x = [prev]
for delta in raznica:
while True:
next = prev + delta
if next in x:
new_x.append(next)
prev = next
else: break
print(new_x)
In [5]:
[0.0799, 0.07991, 0.08, 0.08405]
finished_sandwiches = [dish for dish in sandwich_orders if dish != 'pastrami']
print(finished_sandwiches )
In [1]:
['bokaldilo', 'arepa', 'kebab']
while 'pastrami' in sandwich_orders:
sandwich_orders.pop(sandwich_orders.index('pastrami'))
print(sandwich_orders)
In [2]:
['bokaldilo', 'arepa', 'kebab']
def comfort_count(temperatures):
count = 0
for temp in temperatures:
if 22 <= temp <= 26:
count += 1
returtn count
print(comfort_count(may_2017))
def comfort_count(temperatures):
return sum(1 for temp in temperatures if 22 <= temp <= 26)
def comfort_count(temperatures):
return sum(22 <= temp <= 26 for temp in temperatures)
def mastework(id_key, id_value):
id_join = {}
for k, v in zip(id_key, id_value):
id_join[k] = id_join.get(k, []) + [v]
return {k:v if len(v) > 1 else v[0] for k, v in id_join.items()}
ID_Masterok = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
ID_Master = ['Интендификатор мастера', '654', '2425', '654', '654', '—', '—', '—', '—', '—', '—']
ID_Mastework = mastework(ID_Master, ID_Masterok)
print(ID_Mastework)
In [55]:
{'Интендификатор мастера': 0, '654': [1, 3, 4], '2425': 2, '—': [5, 6, 7, 8, 9, 10]}
from re import findall
from itertools import zip_longest
def change_subs(text, old_sub, new_sub, pos=[1]):
subs = findall(old_sub, text)
for i in pos: subs[i-1] = new_sub
words = zip_longest(text.split(old_sub), subs, fillvalue='')
return ''.join(''.join(elem) for elem in words)
text = 'AAAAdfkjvsAAAA dsjfrfls d AAAAskdnfijdnAAAA kdferjnks AAAAjdfnjAAAA'
old = 'AAAA'
new = 'BB'
pos = [2,3,4]
a = change_subs(text, old, new, pos)
print(a)
In [28]:
AAAAdfkjvsBB dsjfrfls d BBskdnfijdnBB kdferjnks AAAAjdfnjAAAA