I also just discovered that "try-except" lines can't catch a SyntaxError. Why? Because they catch EXCEPTIONS and SyntaxError is not an exception (like, e.g. EOFError or NameError), it's a, well, a syntax error.
A code with a syntax error won't run. This means the "try-except" lines never run either.
Well list comprehensions have been around for a while now, but only recently have I started using them. Now I use them all the time in my applications. Check it out
These were all done in a time period of about 2 days after I discovered it😅
Well, I recently learned that var += 1 is not necessarily the same as var = var + 1 if you use it with mutable values. So using += with lists behaves like append whereas List = List + whatever is a brand new assignment.
And also there will be a major change in Python 3.8 giving us the highly controversial assignment expressions using a socalled walrus operator: :=
This gives you the possibility to assign a name to a value inside an expression like this:
while endCondition:= determineEndCondition():
Here endCondition is assigned the result of determineEndCondition() on each iteration and the while-loop keeps running until endCondition isn't False or None etc.
Another one I just discovered and will be using for more complex projects with many functions/variables:
Especially useful if working on a team as it makes code more readable
A simple example here:
Yep. I used set comprehensions too, one of these codes needed one but I cant remember which😅
Edit: it was the pattern solver. To get the second difference I needed unique values. If there was more than one value in there, then it wasnt a pattern or the program cant solve it
Another one was the Vowel and Consonants one. I wanted unique values for each letter
Sry, should have explained more. Knowing how to add lists is important for recursive programming. So when doing a graph search you can use append or += for mutating a list in global or an upper scope to "store" results (like a path that lead to a specific node). But to find such paths in the first place to you need a new assignment in each function scope giving each scope its own current version of the path. Hope that makes sense.
Ive not delved too deep in recursive programming. I can implement it, but it isnt my "style"...you understand?
I have a couple of semi-decent recursion codes on my sololearn account but nothing serious
Nerderkips its even better after you add a main method
You do this by adding:
if __name__ == "__main__":
# code that will be excecuted if
the program isnt run as a