Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python

Name: Anonymous 2010-05-19 5:58

<code>def add_lists(a, b):
    """
      >>> add_lists([1, 1], [1, 1])
      [2, 2]
      >>> add_lists([1, 2], [1, 4])
      [2, 6]
      >>> add_lists([1, 2, 1], [1, 4, 3])
      [2, 6, 4]
    """
    new_list = []
    i = 0
    while i < len(a):
        new_list += a(i) + b(i)
        i += 1
    return new_list

if __name__ == '__main__':
    import doctest
    doctest.testmod()</code>

TypeError: 'list' object is not callable

How can I fix this?

Name: Anonymous 2010-05-19 7:27

do the "[]" ask it to search the list for the value inside the "[]"?
No, what are you learning python from, because they are filling your mind with bullshit.

When you use the command a[x], you are telling python to get the value stored in the 'a' list at position 'x'.

if so, wouldn't "(index)" be the correct way to call the element of the list?
no, if you are determined to do it with a list method, use a.index(x)

Seriously though, google yourself up a couple of python tutorials and learn the language.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List