469,315 Members | 1,603 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

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

Thanks in advance...
Mar 12 '09 #1
2 1248
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

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

45 posts views Thread by Joh | last post: by
8 posts views Thread by JustSomeGuy | last post: by
11 posts views Thread by William Payne | last post: by
7 posts views Thread by Christian Christmann | last post: by
13 posts views Thread by XXXXXX.working.in.my.blood | last post: by
1 post views Thread by satan | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.