I have a list of models that I iterate through in a for loop getting their performances. I’ve added catboost to my model list, but when I try to add it’s best estimator to a dictionary it gives me an error no other models give me (TypeError: unhashable type: ‘CatBoostRegressor’). Googling and I can’t see a clear way around this
Tag: if-statement
Run Loop If Value Does Not Exist in Database
#update – I fixed the syntax error moving a ), but it still doesn’t work as intended. Now it runs the loop even with a duplicate, which is not the intent. I’m trying to add a list of quotes to a database, but only if the author doesn’t already exist. I’m getting a syntax error here, and no existing posts
if elif when looping thru for loop with stack problem in python
the problem is here: https://binarysearch.com/problems/Unix-Path-Resolution Given a Unix path, represented as a list of strings, return its resolved version. In Unix, “..” means to go to the previous directory and “.” means to stay on the current directory. By resolving, we mean to evaluate the two symbols so that we get the final directory we’re currently in. Constraints n ≤
elif: SyntaxError: invalid syntax
I want to re.search within an if statement but regardless of identation, get syntax error. Is it because elif: has no condition? error message Answer In elif you have if, it requires a condition and you provide none, it should be Using walrus operator (since py3.8) you can improve your code to look like If the code is executed multiple
Is there a way to target a particular item in a list if it is not the first item [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 10 months ago. Improve this question So this is the issue: I want the function to print ‘yes’ as long as P0 is in the list(irrespective of whether P58 is in
Trying to add up points for correct answers in a quiz in Python
I am trying to get a program to add up points for correct answers. I am supposed to have my questions, correct answers, and candidate answers in three separate lists. The questions are to be asked one at a time and I have to return whether or not the answers are correct. I am then supposed to add up the
How to optimise function logic to avoid duplication – python
I have some code below, for a given name that matches pattern with 2 lower case letters (such as ‘aa’), the valid name can be V-aa or X-aa My question is: can I do something like: Answer From your description, I assume that verify_helper() is computationally expensive regardless of names being valid. Now you want to optimize the code, by
Why am I getting Syntaxerror for this while loop? [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 10 months ago. Improve this question
Using recursion to concatenate two strings
My goal is to concatenate two strings using recursion. The input would be str1 = (“long string”) str2 = (“yes so long”) and the output would be: ‘lyoensg ssto rlionngg’ Assumptions are that both strings are the same length. My code as of now is: Im sure Im no where close but I am struggling with making it loop. I
Cleaner Alternative to Nested If/Else
I’m mainly focused on an alternative to if/else’s in create_animal. If there is a more professional way to handle this. In this case, it’s a classifier based on a variable number of traits needed to figure out what the animal is. Since humans are the only animals that speak English, that property is sufficient. But if they roar instead Bear