PYTHONPORTAL Telegram 4498
Возможность Python, которую часто недооценивают -> операции над множествами

Вот пример, как можно удалять или обновлять теги, приводя старые и новые значения к множествам, а затем выполняя операции над множествами

Очистка и приведение к множествам:

existing = {t for tag in old_tags if (t := tag.strip())}
incoming = {t for tag in new_tags if (t := tag.strip())}


🔸tag.strip() удаляет пробелы с начала и конца строки.

🔸t := tag.strip() сохраняет очищенное значение в переменную t.

🔸if (t := tag.strip()) фильтрует пустые строки ("").

Удаление существующих тегов:

updated = existing - incoming
print("Removed tags:", updated)


Добавление новых тегов (без дубликатов):

updated = existing | incoming
print("Added tags:", updated)


👉 @PythonPortal
Please open Telegram to view this post
VIEW IN TELEGRAM



tgoop.com/PythonPortal/4498
Create:
Last Update:

Возможность Python, которую часто недооценивают -> операции над множествами

Вот пример, как можно удалять или обновлять теги, приводя старые и новые значения к множествам, а затем выполняя операции над множествами

Очистка и приведение к множествам:

existing = {t for tag in old_tags if (t := tag.strip())}
incoming = {t for tag in new_tags if (t := tag.strip())}


🔸tag.strip() удаляет пробелы с начала и конца строки.

🔸t := tag.strip() сохраняет очищенное значение в переменную t.

🔸if (t := tag.strip()) фильтрует пустые строки ("").

Удаление существующих тегов:

updated = existing - incoming
print("Removed tags:", updated)


Добавление новых тегов (без дубликатов):

updated = existing | incoming
print("Added tags:", updated)


👉 @PythonPortal

BY Python Portal




Share with your friend now:
tgoop.com/PythonPortal/4498

View MORE
Open in Telegram


Telegram News

Date: |

Unlimited number of subscribers per channel Telegram channels fall into two types: A Hong Kong protester with a petrol bomb. File photo: Dylan Hollingsworth/HKFP. Telegram Android app: Open the chats list, click the menu icon and select “New Channel.” Joined by Telegram's representative in Brazil, Alan Campos, Perekopsky noted the platform was unable to cater to some of the TSE requests due to the company's operational setup. But Perekopsky added that these requests could be studied for future implementation.
from us


Telegram Python Portal
FROM American