Kirt wrote: >> forgot to mention that the fix is to change the first for statement to: >> >> for x in List[:]: >> >> </F>
> Thanx Fredrik Lundh for ur response. I tried ur fix But the output i am > getting is repeated. I'm pretty sure I told you to *loop* over a copy, not *remove* things from a copy. > for x in List[:]: > t2=[] > print x[0] > for y in List: > if x[0]==y[0]: > print y[1],y[2] > t2.append(y) > > for z in t2: > List[:].remove(z) what's that last line supposed to to? here's your *original* code, changed to loop over a copy: for x in List[:]: temp=[] print x for y in List: if x[0]==y[0]: print y[0],y[1] temp.append(y) for z in temp: List.remove(z) print 'rem', z when run on your original data set, this prints your expected output. </F> -- http://mail.python.org/mailman/listinfo/python-list