By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,676 Members | 2,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,676 IT Pros & Developers. It's quick & easy.

Need a help on list....

P: 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
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
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

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