Declaring a python function with an array parameters and passing an array argument to the function call?
Question: I am a complete newbie to python and attempting to pass an array as an
argument to a python function that declares a list/array as the parameter.

I am sure I am declaring it wrong,

here goes:

    
    
    def dosomething(listparam):
             #do something here
    dosomething(listargument)
    

Clearly this is not working, what am I doing wrong?

Thanks


Answer: What you have is on the right track.

    
    
    def dosomething( thelist ):
        for element in thelist:
            print element
    
    dosomething( ['1','2','3'] )
    alist = ['red','green','blue']
    dosomething( alist )  
    

Produces the output:

    
    
    1
    2
    3
    red
    green
    blue
    

A couple of things to note given your comment above: unlike in C-family
languages, you often don't need to bother with tracking the index while
iterating over a list, unless the index itself is important. If you really do
need the index, though, you can use `enumerate(list)` to get `index,element`
pairs, rather than doing the `x in range(len(thelist))` dance.

