Project Euler # 29: Distinct powers in Python
Your docstring is misleading.


The function does not return a sequence; it returns a generator.
It states “for a and b in range(n)”, which is incorrect.  They are in range(2, n+1).  If you don’t want to confuse the issue with range() excluding the last value, say “for a and b in the range from 2 to n, inclusive”.
The problem refers to a “sequence”, where the values are in ascending order and duplicates have been removed, which is completely different from the sequence of values produced by the generator, which is not sorted and can have duplicates.




time1 is a terrible variable name; there is no time2.  Perhaps use start_time.



print((len(...))) has an unnecessary extra pair of parenthesis.



Is distinct_terms(n) too specific of a function?  Perhaps distinct_terms(m, n) could be more general, where you can generate terms for m &lt;= a,b &lt;= n, instead of always the lower limit of m=2.  Or with separate limits for the a and b values.



Python is an easy language to solve this problem in, because \$100^{100}\$ is just another integer in Python, despite having 201 digits.  If you were to solve this in another programming language, one where integers were restricted to (say) 128 bits, what would you do?

With 99 different values for a and b, you have \$99^2 = 9801\$ different \$a^b\$ expressions.  How many of those will be equivalent?  Ie, \$a^b = c^d\$?  For example, \$2^4 = 2^{2*2} = {(2^2)}^2 = 4^2\$.  Can you generalize that?  Can you count the number of occurrences where that happens, and subtract that from 9801?