![]() |
Python list problems
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] = 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] = i TypeError: 'type' object does not support item assignment |
This is pretty messy, please indent the code so we can see whats going on.
|
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] = i return list = [] reset_list(list) for i in range(1,5): put_in_list(i) |
Hmm, mine isnt indented either sorry, how do you indent?
|
| All times are GMT. The time now is 07:23 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.