Longest substring with at most 2 distinct characters
Three small things:

Firstly, docstrings exist. Use them. Put the explanation for how to use your method in them. That means that instead of this:

# Longest substring with at most 2 distinct characters
#
# Given a string S, find the length of the longest substring T that contains at most 2 distinct characters
#
# For example,
#     Given S = "eceba"
#     T is "ece" which it's length is 3

def longest_substring(string):


you have this:

def longest_substring(string):
    """ Longest substring with at most 2 distinct characters
    Given a string S, find the length of the longest substring T that contains t most 2 distinct characters
    For example,
        Given S = "eceba"
        T is "ece" which it's length is 3"""


At least, if I've understood their purpose correctly. 

Secondly, if someone passes in None, that should probably be an error, not a return 0 case. Same if someone passes in a number, Duck, or any other invalid type.

Thirdly, according to PEP8, the official style guide, none of your lines should be longer than 80 characters. The (new) second line violates this; it even did before. Just split it in half and you're good.