python-discord / meta

Issue tracker for suggestions and other questions relating to our community
https://pythondiscord.com
31 stars 5 forks source link

new tag !in #211

Open kortycodes opened 1 year ago

kortycodes commented 1 year ago

Heya. I wrote a message for the bot for !in I read through the !contribute bit but not too sure how to submit. If there’s a different way to do this, please let me know.

Feed back is of course welcome and highly appreciated.

I have another message regarding the use of a condition in if. Let me know if I can post that here as well or should do something else with it.

========= start of message ==== in used to see if a is part of b. a in b return a boolean True/False. Where b is an iterable.

Example

a = 'foo'
b = ['foo', 'bar', 'baz']
c = ['bar' ,'baz']

print(f'{a} in {b}? ', a in b)
print(f'{a} in {c}? ', a in c) 

The result of the function can be used directly to enter an if statement. Rather do this:

if a in b:
    pass

Than this:

if (a in b) == True:
    pass

====== end of message =====

Potentially also part of the message, although I’m not too sure if it is the best way to do things:

=== optional ==== If a is a list we have to use all():

a = ['foo', 'bar']
b = ['foo', 'bar', 'baz']

# Checks if all elements of a are in b.
print(all([c in b for c in a]))

==== end ====

Have a goodie! -korty.codes