-3

I'm trying to make a loop where it changes the variable each time in the loop.

list0 = []
list1 = []
list2 = []

value = 0

for _ in range(3):
    list_l = ("list" + str(value))
    list_l.append("Apple")
    value += 1
    print(list0)
    print(list1)
    print(list2)

Getting error

AttributeError: 'int' object has no attribute 'append'
martineau
  • 112,593
  • 23
  • 157
  • 280
  • 2
    This is not the error your code generates. And even then, how is the error unclear? – Julien Jul 30 '21 at 01:00
  • 1
    You should be getting the error `'str' object has no attribute 'append'` because `list_l` contains a string. – Barmar Jul 30 '21 at 01:07

1 Answers1

0

Is this what you are looking for?
https://www.online-python.com/LzbkxdmNA8

list0 = []
list1 = []
list2 = []
LargeList = [list0,list1,list2]

value = 0

for _ in range(3):
    value+=1;
    LargeList[_].append("apple-"+str(value))

print(list0)
print(list1)
print(list2)

Output:

['apple-1']
['apple-2']
['apple-3']
Alexander Smith
  • 134
  • 1
  • 5
  • 1
    By convention naming a variable `_` is usually used to indicate the value is ignored — which is obviously not the case here. It's also best to not post links to offsite resources that are likely going to disappear eventually. Lastly, you've offered no explanation about how your code and OP's are different. – martineau Jul 30 '21 at 01:06