How to make a list of characters in Python
Question: My exam question asks me to take two letters as inputs, and display all
letters in the alphabet between the two inputs (inclusively). It also needs to
do this in the order the user input them (so GA produces `GFEDCBA` not
`ABCDEFG`). How would I approach this task?


Answer: 
    >>> import string
    >>> def letterList (start, end):
            # add a character at the beginning so str.index won't return 0 for `A`
            a = ' ' + string.ascii_uppercase
    
            # if start > end, then start from the back
            direction = 1 if start < end else -1
    
            # Get the substring of the alphabet:
            # The `+ direction` makes sure that the end character is inclusive; we
            # always need to go one *further*, so when starting from the back, we
            # need to substract one. Here comes also the effect from the modified
            # alphabet. For `A` the normal alphabet would return `0` so we would
            # have `-1` making the range fail. So we add a blank character to make
            # sure that `A` yields `1-1=0` instead. As we use the indexes dynamically
            # it does not matter that we have changed the alphabet before.
            return a[a.index(start):a.index(end) + direction:direction]
    
    >>> letterList('A', 'G')
    'ABCDEFG'
    >>> letterList('G', 'A')
    'GFEDCBA'
    >>> letterList('A', 'A')
    'A'
    

Note that this solution allows any kind of alphabet. We could set `a = ' ' +
string.ascii_uppercase + string.ascii_lowercase` and get such results:

    
    
    >>> letterList('m', 'N')
    'mlkjihgfedcbaZYXWVUTSRQPON'
    

And who needs ASCII when you have full unicode support?

    
    
    >>> a = ' あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわを'
    >>> letterList('し', 'ろ')
    'しすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろ'
    

