On 03/03/2015 06:50, Phil wrote:
Thank you for reading this.
Python 3 under Linux.

I'd like to set up a two dimensional list of counters as follows;

count = [
             [0],
             [0],
             [0]
         ]

And then increment the first counter as follows;

count [0] += 1

This fails with the following error;

TypeError: 'int' object is not iterable

The array module looks like the answer because it seems to function in
the same way as an array under C. However, it seems to me that I should
be able to do the same thing with a list.

Is there a way to add a value to a list of ints?


You are trying to increment the first element of count which is itself a list containing one element. You actually need:-

count[0][0] +=1

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to