R
R
ripjakeyh2019-06-20 15:31:36
Python
ripjakeyh, 2019-06-20 15:31:36

Execute if variable equals at least one element from array (Python)?

Let's say that the id variable gets the identifier of the user who wrote the message.
Let's say the array is user = ["334455", "556677"]
How do I do this? If at least one element from the array is equal to the variable then: ...
I tried this, but it didn't work:

if id == user[0] or user[1]:
if user[0] or user[1] in id:

Yes, yes, I'm dumb

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
milssky, 2019-06-20
@ripjakeyh

if id in set(user):
    #тут что-то делаем

It will work provided that the id is a string. If not a string, don't forget the appropriate conversion

T
tsarevfs, 2019-06-20
@tsarevfs

Maybe so? Just make sure that id is not a number but also a string.
if id in user:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question