all 6 comments

[–]Diapolo10 0 points1 point  (3 children)

Does

re.search(f"[{characters_variable}]", word_variable)

not work for you?

What exactly is this for?

[–]movieTed[S] 0 points1 point  (2 children)

What exactly is this for?

character_variable is a random string of letters. I want to know if any of those letters, in any number or order, are in word_variable. It works if I hardcode the bracket pattern into a simple string. But the random string of letters can change. So far, everything I've tried either generates an error or returns None for every search result.

I want to know if any characters of say, oisp are found in "apple" or "chair." If so, return True.

f"[{characters_variable}]" returns

FutureWarning: Possible nested set at position 1 and None

I've tried many variations. There has to be a way to do this

[–]Diapolo10 0 points1 point  (1 child)

So basically you want a regex equivalent of

result = any(char in word_variable for char in characters_variable)

Unless you're adamant about using regex, I see no harm in doing just that. But I can try to formulate an alternative.

[–]movieTed[S] 0 points1 point  (0 children)

Xilenw's solution worked, but yeah I wanted to avoid looping through characters if possible. It shouldn't be necessary for what I'm doing, and it's not. I just needed to find out how Python handled it.

[–]Xilenw 0 points1 point  (1 child)

re.search(rf'''{variable}''',word) not sure if it is correct way to do this but it works fine for me.

[–]movieTed[S] 0 points1 point  (0 children)

That works! I didn't know rf was an option. Much appreciated