On Aug 29, 2009, at 12:23 AM, Michael M Mason wrote:

i wrote:
def pack(in_seq):
        out_list=[]
        x = 1
        ll=[1, 1]
        for each in in_seq:
                ll[0] = x
                ll[1] = each
                out_list.append(ll)
                #print ll
                x = x + 1
        print out_list

Variable out_list consists of list ll repeated however many times. Each time you change ll you're changing it everywhere it appears in out_list.
That is, what's being appended to out_list isn't a copy of ll, it's a
pointer to ll.

You need something like:-

       out_list.append([ll[0],ll[1]])

Right... ugh.. Totally forgot about that. Python 101. I don't know why my brain resists that idea. Every time i let python alone a while and come back to it i get bit by this.



And you need to add a return at the end of the function, otherwise it
returns None:

        return out_list


That, of course, i know... I was messing around debugging of course.

Thanks for the response.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to