Denote if string contains any member of a set of characters

273 Views Asked by At

I come from a computer science background and trying to properly document the following python if statement.

for char in X:
    if char in "abcdefghijklmnopqrstuvwxyz":
        return true
        break

Here I am checking if the string contains any of the alphabet characters. No matter the position or frequency, it's true as long as X contains any member of "abcdefghijklmnopqrstuvwxyz". When X = "hello" is true. X = "123" is false. And X = "hello 123" is true.

How would I mathematically denote this? I don't think the following is possible as it checks if the entire $X$ sequence is a member of $g$.

$g = \{a, b, c, \dots, z\}$

if $X \in g$ then

Would it be a subset? if $X \subset g$ then

Preferably I wouldn't have to denote the character loop as it's an unimportant detail. Just if the string contains any alphabet character

2

There are 2 best solutions below

0
On

Let s be a string, S the set of the symbols in s,
and A the set of all letters of the alphabet.

That s contains a letter is expressed
S $\cap$ A is not empty.

0
On

First of all, I would rather use $A$ (for alphabet) for the set $\{a, b, c, \dots, z\}$ and $C$ for the set of all characters (char). With this notation, a string $s$ of $C^*$ satisfies your condition if and only if $s \in C^*AC^*$. In other words, your condition can be mathematically represented by a regular language.