#๐ if "(]" in s then output false but does true
30 messages ยท Page 1 of 1 (latest)
@tribal hawk
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Hey @tribal hawk!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
"()" or "([])" in s doesn't work like you expect
2 things
- why u inheriting from object
- that
orisnt doing what u think it is
!or-gotcha
When checking if something is equal to one thing or another, you might think that this is possible:
# Incorrect...
if favorite_fruit == 'grapefruit' or 'lemon':
print("That's a weird favorite fruit to have.")
While this makes sense in English, it may not behave the way you would expect. In Python, you should have complete instructions on both sides of the logical operator.
So, if you want to check if something is equal to one thing or another, there are two common ways:
# Like this...
if favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon':
print("That's a weird favorite fruit to have.")
# ...or like this.
if favorite_fruit in ('grapefruit', 'lemon'):
print("That's a weird favorite fruit to have.")
@tribal hawk since in returns a boolean, you could return that directly
this is what i did
class Solution(object):
def isValid(self, s):
if s in ("()", "([])", "()[]{}"):
return True
else:
return False
Hey @tribal hawk!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
but like this idk how to make it so no matter what is in s as long as the brackets are closed it will be true
bc im saying only if those 3 strings are inputed then true but it will say false if its {[()]} which should be true
!e ```py
print("5" in "456")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
True
boolean
regex?
idk how to like make it automatic
please don't implement matching parenthesis with a regex
would you like a direct statement of how to do this or a hint?
whats wrong with it?
hint
totally unsuitable and very hacky
the hint is: you will definetly need to scan over the characters on by one. you will also definetly need to keep track of some state while you do
damn ok
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.