Problem with List of List

Kirt moqtar at gmail.com
Sat Aug 26 01:18:55 EDT 2006


I am a newbie and stuck over this for a week
I have a code
==================CODE=============
List=[['1', 'a', '6'], ['1', 'b', '6'], ['1', 'c', '6'],
        ['1', 'd', '6'],['2', 'a','6'], ['2', 'b', '6'],
        ['2', 'c', '6'], ['2', 'd', '6'], ['3', 'a', '6'],
        ['3','b', '6'], ['4', 'a', '6'], ['4', 'b', '6']]


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
=======================================
the output i am getting at Present is:
==========Current OP=====================
['1', 'a', '6']
1 a
1 b
1 c
1 d
rem ['1', 'a', '6']
rem ['1', 'b', '6']
rem ['1', 'c', '6']
rem ['1', 'd', '6']

['2', 'b', '6']
2 a
2 b
2 c
2 d
rem ['2', 'a', '6']
rem ['2', 'b', '6']
rem ['2', 'c', '6']
rem ['2', 'd', '6']

['4', 'a', '6']
4 a
4 b
rem ['4', 'a', '6']
rem ['4', 'b', '6']
================================================
i am wondering where " ['3', 'a', '6'], ['3','b', '6']" is not showing.

I want an output like this:

['1', 'a', '6']
1 a
1 b
1 c
1 d
rem ['1', 'a', '6']
rem ['1', 'b', '6']
rem ['1', 'c', '6']
rem ['1', 'd', '6']

['2', 'b', '6']
2 a
2 b
2 c
2 d
rem ['2', 'a', '6']
rem ['2', 'b', '6']
rem ['2', 'c', '6']
rem ['2', 'd', '6']

['3', 'a', '6']                 ================
3 a                              why is this portion
3 b                               not present in my current op
rem ['3', 'a', '6']
rem ['3', 'b', '6']           =================

['4', 'a', '6']
4 a
4 b
rem ['4', 'a', '6']
rem ['4', 'b', '6']

I hope ull wil get what i am trying to say. Can anyone help: Thanx




More information about the Python-list mailing list