I'm a Python newbie crossing over from C. I'm basically trying implement logic equivalent to an array of array pointers in C.
I want to append one item to the ends of a bunch of lists by iterating over a list of these lists. I have the following code:
data = [10, 20, 30] list1 = list2 = list3 = list() lists = [list1, list2, list3] for i in range(len(data)): lists[i].append(data[i]) for lst in lists: print lst
It's result, however, is:
[10, 20, 30] [10, 20, 30] [10, 20, 30]
instead of:
[10] [20] [30]
I can't explain why this code fails to produce the desired output, and is there some other way of doing this?