Grouping Elements of a List based on attributes of the elements
<p>I have the following list</p>

<pre><code>List=[
    ('G1', 'CFS', 'FCL', 'R1'),
    ('G3', 'LOOSEFREIGHT', 'MIXEDLCL', 'R9'),
    ('G4', 'CFS', 'FCL', 'R10'),
    ('G2', 'LOOSEFREIGHT', 'LCL', 'R4'),
    ('G1', 'CFS', 'FCL', 'R2'),
    ('G2', 'LOOSEFREIGHT', 'LCL', 'R5'),
    ]
</code></pre>

<p>Now I want to group this elements of List first by index [1] (i.e. CFS and LOOSEFREIGHT) together and for those elements which are grouped together for LOOSEFREIGHT, I want to further divide them into different groups based on index[2] (i.e. LCL or MIXEDLCL).</p>

<p>So essentially I want them grouped into different lists and my solution should be  of the form</p>

<pre><code>New_List=[
    [
        ('G1', 'CFS', 'FCL', 'R1'),
        ('G1', 'CFS', 'FCL', 'R2'),
        ('G4', 'CFS', 'FCL', 'R10')
    ],
    [
        ('G2',  'LOOSEFREIGHT', 'LCL', 'R4'),
        ('G2', 'LOOSEFREIGHT', 'LCL', 'R5')
    ],
    [
        ('G3', 'LOOSEFREIGHT', 'MIXEDLCL', 'R9')
    ],
    ]
</code></pre>

<p>How do I do it?</p>

<p>I managed to do divide them into different lists based on index [1] however I was not able to further divide them based on index [2]</p>

<p>Any help is appreciated.</p>
