PRO_PYTHON_CODE Telegram 1349
🖥 Как проверить содержится ли в строке какое-то слово из списка?

▶️Например есть список:
words = ["Авто", "Велосипед", "Самолет"]

И такая строка:

st = "Быстрый автомобиль"

Нужно вернуть True, т.к. в строке есть слово "авто" из списка.


▶️Можно вот так:

def is_part_in_list(st, words):
for word in words:
if word.lower() in st.lower():
return True
return False

print(is_part_in_list(st, words))


*️⃣Изящный вариант в одну строку:

print(any(word.lower() in st.lower() for word in words))


*️⃣Или можно вот так с маппингом вместо цикла для разнообразия:

print(any(map(text.lower().__contains__, map(st.lower, words))))


@pro_python_code
Please open Telegram to view this post
VIEW IN TELEGRAM



tgoop.com/pro_python_code/1349
Create:
Last Update:

🖥 Как проверить содержится ли в строке какое-то слово из списка?

▶️Например есть список:

words = ["Авто", "Велосипед", "Самолет"]

И такая строка:

st = "Быстрый автомобиль"

Нужно вернуть True, т.к. в строке есть слово "авто" из списка.


▶️Можно вот так:

def is_part_in_list(st, words):
for word in words:
if word.lower() in st.lower():
return True
return False

print(is_part_in_list(st, words))


*️⃣Изящный вариант в одну строку:

print(any(word.lower() in st.lower() for word in words))


*️⃣Или можно вот так с маппингом вместо цикла для разнообразия:

print(any(map(text.lower().__contains__, map(st.lower, words))))


@pro_python_code

BY Python RU




Share with your friend now:
tgoop.com/pro_python_code/1349

View MORE
Open in Telegram


Telegram News

Date: |

5Telegram Channel avatar size/dimensions Just as the Bitcoin turmoil continues, crypto traders have taken to Telegram to voice their feelings. Crypto investors can reduce their anxiety about losses by joining the “Bear Market Screaming Therapy Group” on Telegram. Avoid compound hashtags that consist of several words. If you have a hashtag like #marketingnewsinusa, split it into smaller hashtags: “#marketing, #news, #usa. The initiatives announced by Perekopsky include monitoring the content in groups. According to the executive, posts identified as lacking context or as containing false information will be flagged as a potential source of disinformation. The content is then forwarded to Telegram's fact-checking channels for analysis and subsequent publication of verified information. The optimal dimension of the avatar on Telegram is 512px by 512px, and it’s recommended to use PNG format to deliver an unpixelated avatar.
from us


Telegram Python RU
FROM American