Python list problems

Discussion in 'Software' started by wanna-python, Jan 22, 2011.

  1. wanna-python

    wanna-python

    Joined:
    Jan 22, 2011
    Messages:
    1
    Newby alert! - I'm new to Python

    Why does this program do the following:

    list-test.py

    def reset_list(list):
    list = []
    for i in range(0,9):
    list.append('')
    return list

    def put_in_list(i):
    list = i
    return

    reset_list(list)

    for i in range(1,5):
    put_in_list(i)

    c:\python27\dev>python list-test.py
    Traceback (most recent call last):
    File "list-test.py", line 14, in <module>
    put_in_list(i)
    File "list-test.py", line 8, in put_in_list
    list = i
    TypeError: 'type' object does not support item assignment
    wanna-python, Jan 22, 2011
    #1
    1. Advertising

  2. wanna-python

    Vort3x

    Joined:
    Feb 28, 2011
    Messages:
    4
    This is pretty messy, please indent the code so we can see whats going on.
    Vort3x, Feb 28, 2011
    #2
    1. Advertising

  3. wanna-python

    Vort3x

    Joined:
    Feb 28, 2011
    Messages:
    4
    Your list you use in the first method is only local to that method I think?
    This should work.

    def reset_list(list):
    for i in range(0,9):
    list.append('')
    return list

    def put_in_list(i):
    list = i
    return

    list = []
    reset_list(list)

    for i in range(1,5):
    put_in_list(i)
    Vort3x, Feb 28, 2011
    #3
  4. wanna-python

    Vort3x

    Joined:
    Feb 28, 2011
    Messages:
    4
    Hmm, mine isnt indented either sorry, how do you indent?
    Vort3x, Feb 28, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?Q?Frisbee=AE?=

    OT: Which Monty Python Character Are You?

    =?iso-8859-1?Q?Frisbee=AE?=, May 24, 2004, in forum: MCSE
    Replies:
    9
    Views:
    581
  2. =?Utf-8?B?U2FuZHdvcm0=?=

    Name that Python!!!! Yes, you too could win!!!

    =?Utf-8?B?U2FuZHdvcm0=?=, Jun 9, 2004, in forum: MCSE
    Replies:
    16
    Views:
    559
    =?Utf-8?B?U2FuZHdvcm0=?=
    Jun 10, 2004
  3. English Teacher

    GOOD BOOK for PYTHON/Linux

    English Teacher, Oct 21, 2003, in forum: Digital Photography
    Replies:
    1
    Views:
    349
    Mark Herring
    Oct 21, 2003
  4. Robert Kaiser
    Replies:
    3
    Views:
    877
    Frank Malczewski
    May 11, 2004
  5. partyin
    Replies:
    0
    Views:
    1,004
    partyin
    Feb 21, 2012
Loading...

Share This Page