amarao: (Default)
[personal profile] amarao

Проверка, что в командной строке есть аргумент, начинающийся с --ansible-inventory

if any([a.startswith("--ansible-inventory") for a in sys.argv]):
    ...

Date: 2022-06-18 04:18 pm (UTC)
yurikhan: (Default)
From: [personal profile] yurikhan

О, не, не всегда.

Кроме задачи «проверить существование»:

if any(p(x) for x in xs):
    ...

иногда встречается задача «проверить существование и предъявить один пример»:

x0 = next((x for x in xs if p(x)), None)
if x0 is not None:
    ...

В особом случае, когда None — допустимый x, можно завести отдельный sentinel:

sentinel = object()
x0 = next((x for x in xs if p(x)), sentinel)
if x0 is not sentinel:
    ...

А также задача «проверить существование и предъявить все примеры».

xs0 = [x for x in xs if p(x)]
if xs0:
    ...

Profile

amarao: (Default)
amarao

February 2026

S M T W T F S
123456 7
8910111213 14
15161718192021
22232425262728

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 25th, 2026 10:40 pm
Powered by Dreamwidth Studios