Q:

Can't find the reason for the error in my code in python

I am beginner in Python and learning through Learn Python the Hard Way. 
Unfortunately, I keep getting an error and don't know why. 
Here's the code:
def new(num_buckets=256): # Creates list aMap and fills it with 256 empty lists. 
    """ Initializes a Map with the given number of buckets.""" 
    aMap = []
    for i in range(0, num_buckets):
        aMap.append([])
    return aMap

new()
print aMap

strangely enough I keep getting a message saying that aMap is not defined even though I just ran a function creating it as a bunch of empty buckets inside a list.  
Thanks for your help. 

A:

new() returns aMap, but you never store that anywhere.   You want:
aMap = new()

Generally speaking, unless you explicitly state otherwise (via a global or nonlocal1 statement), a name only exists in the scope where it was defined.   In this case the name aMap only exists inside the function new.   To make that name exist outside the function, you need to assign something to it. 
1Python3.x only

