Collatz Sequence in Python
Variable Names

You use a, b, c, d, e, f, and g to refer to important things. I started trying to keep track of what each one meant and then gave up. I have no idea. Give things meaningful names. Apparently d is the number with the longest sequence, whose length is e - which is certainly not obvious from the names!

Chaining

To find the length of the collatz chain for some number, n, involves also finding the length of the collatz chain for every other number in that chain. However, you don't store that information anywhere, so it's lost. 

Furthermore, you calculate it TWICE:

if collatz_length(f)&gt;e:
    d=f
    e=collatz_length(f)


So you're recalculating every chain every time twice. That's an enormous amount of extra work. Lastly, you're assuming that the largest starts halfway through. That isn't necessarily true, given that collatz(n) &gt; n for odd n... 

Saving State

You save some state in a, but that ends up with you having to do a linear search through a list... which will fail most of the time, but it'll take a long time to fail. At the very least, you could store things in a set(), which is O(1), but even then, you're storing the wrong state. You're storing numbers you've seen before, but what you should store is the chain lengths of the numbers you've seen before. That is...

Memoize

This is a problem that lends itself extremely naturally to memoization, so we can just do that:

@memoize
def collatz_length(n):
    if n == 1:
        return 1
    else:
        return 1 + collatz_length(collatz(n))


And then just stick that into max:

longest_num = max(range(1, 1000001), key=collatz_length)
print(longest_num)
print(collatz_length(longest_num))