Have you checked your errors? Your code is written for a single list yet you’re supplying a list of sublists.
I use Try/Except for two things. 1) Catching specific conditions to return a warning and 2) “lazy” filtering or handling of expected problems.
One example would be the difference between parameters that represent a string and parameters that represent an object but read as a string. I could write something like:
try:
val = element.Parameter.AsString()
except:
val = element.Parameter.AsValueString()
This lets me attempt to get the value using AsString() but if that method doesn’t exist, rather than just erroring, the code will continue with what’s in the exception loop and us AsValueString().
EDIT: I forgot a very important third reason for Try/Except loops: troubleshooting. You can add a Try loop to determine where exactly you might be hitting exceptions and essentially “skip” parts of code that may be problematic.
To add to Jacob’s point on flow control, try/except is super handy when you’re expecting something to sometimes fail (e.g. a user gets the matching name of a view wrong). Best practice is to specify the error if possible so you can catch the error(s) as intended though. They’re a bit of a necessary evil given Dynamo typically wont get through nulls in most cases, usually I use them to yield ‘None’ in a value list, and often will make a ‘did it work’ output as well (made of booleans, so it can be used as a mask on the original data to allow it to proceed on in a filtered state) so they will generate an error technically, but handle the step that will cause that and proceed onward.
Iirc, the syntax for catching specific errors is:
try:
#a thing
except ErrorType as error:
#catch the error
Give I’ve been scolded by programming chums for using them in the past, I believe the principle is they are a brute force/last resort type statement if optimisation is a goal in your code. A good example of avoiding a try/except is the check for whether a view is placed as a viewport when trying to place views on sheets versus running it through a try/except. The boolean outcome can be used to drive an if/else pathway where the else just bypasses the already placed view.
To grasp these concepts, I suggest you take a structured Python course.
See the one I took below offered on edx. It’s a two-week course that runs through the basics of the Python language. To get more in-depth there is a follow-up course on data structures which I also recommend.
Cheers.