After listening to an advice regarding my code, I found the algorithm behind a generating code function, which allows me to procedurally generate code that would evaluate itself.
[(a_0, a_1, a_2) for a_0, a_1, a_2 in product(range(1,100),repeat=3) if a_0 ** 2 + a_1 ** 2 == a_2 ** 2]
This is the result of the coding. As you can see, I am using itertools product function, which as I know needs to be optimised. If this post gets viewed enough, I will publish the code that generated this.
I researched about what could I do. First, I realised that in any pythagorean triple the last number of the tuple (i.e. (3,4,5)) is bigger than the other numbers in the triple, so I put ||max(-the variables I used) < the biggest variable| in the function:
[(a_0, a_1, a_2) for a_0, a_1, a_2 in product(range(1,100),repeat=3) if a_0 ** 2 + a_1 ** 2 == a_2 ** 2 and max(a_0,a_1) < a_2]
But I don't really now if this accelerates the function. Is there a better way to optimise this function? If you have any answers or questions, I would greatly appreciate them!
Edit: Thanks to the petition of @Stef of using itertools' combination function instead of product, but sadly that function doesn't fasten the process.
Also I'm talking about optimising this function, not about making it work (it does work).
Edit2: I tested out many times the function with product and with combinations, and it turns out combinations is faster by a factor of over 6 in triples. It does greatly optimise the function, so thanks to @Stef for helping me out.
Also, if there is a function that can optimise this to the maximum, I would really appreciate it. The function can be from any module, including built-in functions if possible.