0

Here is some code that I have written:

class MyClass:
    listt=[]
    def __init__(self):
        ""  

instancelist = [ MyClass() for i in range(29)]
for i in range(0,29):
    instancelist[i].listt[i].append("ajay")
print instancelist

I am getting this error:

File "/home/aj/workspace/PythonTutorials/basics/builtFun.py", line 16, in <module>
    instancelist[i].listt[i].append("ajaajayy")
IndexError: list index out of range

How can I solve this?

2
  • What was that edit for? Commented Feb 25, 2013 at 5:01
  • Why are you creating a class that only contains a list instance? Commented Feb 25, 2013 at 5:44

1 Answer 1

1
class MyClass:
    listt=[]
    def __init__(self):
        ""  

instancelist = [ MyClass() for i in range(29)]
for i in range(0,29):
    instancelist[i].listt.append("ajay")
print instancelist

Fixed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.