def process_list(lst):
# Убираем нули
lst = [x for x in lst if x != 0]
# Объединяем одинаковые элементы справа налево
i = len(lst) - 1
while i > 0:
if i < len(lst) and i - 1 >= 0 and lst[i] == lst[i - 1]:
lst[i] *= 2
lst.pop(i - 1)
# После удаления элемента, сдвигаем индекс,
# чтобы не выйти за пределы и проверить новую пару
i = min(i, len(lst) - 1)
else:
i -= 1
# Добавляем недостающие нули в начало списка
return [0] * (4 - len(lst)) + lst
data = [
[2, 2, 2, 2], # Ожидаем [0, 0, 0, 8]
[2, 0, 2, 2], # Ожидаем [0, 0, 2, 4]
[2, 4, 2, 2], # Ожидаем [0, 0, 2, 8]
[2, 4, 4, 2] # Ожидаем [0, 2, 8, 2]
]
for y in data:
print(process_list(y))
fetchall()
, которым вы загружаете все данные в память.Buttons available only in inline keyboards:
keyboardButtonUrl - Open the URL, showing a "Do you want to open this URL?" prompt (unless the URL is one of the internal URIs, in which case the URL should be opened right away)
try:
comments_count = await client.get_discussion_replies_count(channel_id, message_id)
except Exception as e:
print(f'Ошибка при получении комментариев: {e}')
comments_count = 'Комментарии выключены'