Sunday, 2 June 2013

How to group this python list?

How to group this python list?

I have the following array:
[1 , 2]
[1 , 3]
[1 , 4]
[2 , 3]
[2 , 4]
[5 , 1]
I want to print an output like the following:
    "Items related to 1:"

        2, 3, 4, 5 *note this last one was on the first column and 1 in the second

    "Items related to 2:

        3, 4

    "Items related to 3:"
        1, 2

    "Items related to 4:"
        1, 2

    "Items related to 5:"
        1
Any ideas?

No comments:

Post a Comment