insert a tkinter progress bar in a List Comprehensions of Python
If you are concerned about performance, remove the call to self.update()
. It will slow your loop down by up to three orders of magnitude. At the very least you should call it only every 1,000 iterations or so.
In a quick test, I can do 10,000 simple calculations that result in 1% of the values being appended to a loop in about .0016 seconds. When I add a call to update
in the loop, the time expands to 1.0148 seconds.
You said in a comment you have 80 million rows to iterate over. My same code can process 80 million calculations in 12 seconds, versus over 2 hours when I add in a call to update.
Converting your code to using a list comprehension will have a negligible effect compared to removing or reducing the calls to update.