Connecting Tech Pros Worldwide Help | Site Map

Need a help on list....

Newbie
 
Join Date: Feb 2009
Posts: 11
#1: Mar 12 '09
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's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,561
#2: Mar 12 '09

re: Need a help on list....


Create a copy of list4 for sorting.
Expand|Select|Wrap|Line Numbers
  1. def sorted(s, d=1):
  2.     ''' Return a sorted copy of a list. If 'd' == -1,
  3.     reverse the sort.'''
  4.     def cmpitems(a, b):
  5.         if d == 1:
  6.             return cmp(a, b)
  7.         return -cmp(a, b)
  8.     s = s[:]
  9.     s.sort(cmpitems)
  10.     return s
  11.  
  12. list1 = ['d', 'a', 'c', 'x', 'y']
  13. list2 = list1
  14. list3 = list1
  15. list4 =[list1[0], list1
  16.  
  17. 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.
Newbie
 
Join Date: Feb 2009
Posts: 11
#3: Mar 13 '09

re: Need a help on list....


thxs for the help.....
Reply

Tags
list