I’ve written a time_calculator, it works fine, the code is very compact; maybe too compact. The first line is
start_mins = 60 * int(start.split().split(':')) + int(start.split().split(':')) + 720 if 'PM' in start.split() else 60 * int(start.split().split(':')) + int(start.split().split(':'))
Its an inline if else statement, with only ‘start’ (ie ‘8:16 PM’) as input, and only ‘start_mins’ (the time in ‘start’, expressed in minutes, ie 1216 in this case) as output.
Difficult to read, and difficult to debug without documenting all steps that led up to this, but the idea was to a) keep the number of lines down, and b) create something that executes fast.
My question is, would this code execute faster if, instead of repeatedly refering to list.split indexes, I assigned their values to variables? Does the interpreter/compiler keep copies of indexes of split lists in RAM to refer to, or does it have to re-split it each time it encounters a new reference to it in code? I’m guessing that’s what would affect execution speed the most.
I’ll put the code up on replit when I feel like I’ve understood this issue.
Thanks! And happy new year to all.