472,145 Members | 1,385 Online

# Need a help on list....

21
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..

Mar 12 '09 #1
2 1291
bvdet
2,851 Expert Mod 2GB
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.
Mar 12 '09 #2
neeru29
21
thxs for the help.....
Mar 13 '09 #3