Need a help on list....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neeru29
    New Member
    • Feb 2009
    • 21

    Need a help on list....

    Let us assume that we have 4 different list which are independent of each other, But value in it are dependent of each other.


    Say:-

    List1 = [ ]
    List2 = [ ]
    List3 = [ ]
    List4 = [ ]

    i.e
    value at List4[5] dependent with List1[5], List2[5], List3[5]

    If i'm sorting List4 i don't want to loose the dependency of the values which are interconnected.

    How can i do that..

    Thanks in advance...
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Create a copy of list4 for sorting.
    Code:
    def sorted(s, d=1):
        ''' Return a sorted copy of a list. If 'd' == -1,
        reverse the sort.'''
        def cmpitems(a, b):
            if d == 1:
                return cmp(a, b)
            return -cmp(a, b)
        s = s[:]
        s.sort(cmpitems)
        return s
    
    list1 = ['d', 'a', 'c', 'x', 'y']
    list2 = list1
    list3 = list1
    list4 =[list1[0], list1
    
    list4_sorted = sorted(list4)
    The sorted list will no longer be dependent on the other lists. You may be able to design a class object to maintain the dependency of several lists.

    Comment

    • neeru29
      New Member
      • Feb 2009
      • 21

      #3
      thxs for the help.....

      Comment

      Working...