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

Tracking sorted items in a zip()ed list

P: 9
firstly i want to thatn all you guys for the help on the sorting program


i have a problem that i tried but 'm unable to solve ...

u guys helped a lot in my previous post ..
so please help me now ..


'm using windows



heres my code

Expand|Select|Wrap|Line Numbers
  1. a = [3, 2, 1]
  2. b = [7, 5, 3]
  3. c = [56, 242, 4]
  4. r = [31, 146, 124]
  5.  
  6. t = zip(a, b, c, r)
  7. print t
  8. # [(31, 7, 56, 3), (2, 5, 242, 146), (1, 3, 4, 124)]
  9. for i, intTuple in enumerate(t):
  10.     t[i] = sorted(intTuple)
  11. print t
  12. # [[3,  7, 31,56], [2, 5, 146, 242], [1, 3, 4, 124]]
  13.  
  14. print t[:1]
  15.  
now if i print t[:1]

the output will be
[3,7,31,56]

my problem is ... how can i print the a,b,c,d for the coresponding vectors

i.e


i want to print for the above axample ... [3,7,31,56 ] - [a,b,r,c]

and also print
a
b
c
d
Nov 26 '07 #1
Share this Question
Share on Google+
3 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
firstly i want to thatn all you guys for the help on the sorting program


i have a problem that i tried but 'm unable to solve ...

u guys helped a lot in my previous post ..
so please help me now ..


'm using windows



heres my code

Expand|Select|Wrap|Line Numbers
  1. a = [3, 2, 1]
  2. b = [7, 5, 3]
  3. c = [56, 242, 4]
  4. r = [31, 146, 124]
  5.  
  6. t = zip(a, b, c, r)
  7. print t
  8. # [(31, 7, 56, 3), (2, 5, 242, 146), (1, 3, 4, 124)]
  9. for i, intTuple in enumerate(t):
  10.     t[i] = sorted(intTuple)
  11. print t
  12. # [[3,  7, 31,56], [2, 5, 146, 242], [1, 3, 4, 124]]
  13.  
  14. print t[:1]
  15.  
now if i print t[:1]

the output will be
[3,7,31,56]

my problem is ... how can i print the a,b,c,d for the corresponding vectors

i.e


i want to print for the above example ... [3,7,31,56 ] - [a,b,r,c]

and also print
a
b
c
d
Can you provide us with the definition of 'd'?
Nov 26 '07 #2

P: 9
'm sorry what i meant was the array names ... a b r c
Nov 27 '07 #3

bvdet
Expert Mod 2.5K+
P: 2,851
firstly i want to thatn all you guys for the help on the sorting program


i have a problem that i tried but 'm unable to solve ...

u guys helped a lot in my previous post ..
so please help me now ..


'm using windows



heres my code

Expand|Select|Wrap|Line Numbers
  1. a = [3, 2, 1]
  2. b = [7, 5, 3]
  3. c = [56, 242, 4]
  4. r = [31, 146, 124]
  5.  
  6. t = zip(a, b, c, r)
  7. print t
  8. # [(31, 7, 56, 3), (2, 5, 242, 146), (1, 3, 4, 124)]
  9. for i, intTuple in enumerate(t):
  10.     t[i] = sorted(intTuple)
  11. print t
  12. # [[3,  7, 31,56], [2, 5, 146, 242], [1, 3, 4, 124]]
  13.  
  14. print t[:1]
  15.  
now if i print t[:1]

the output will be
[3,7,31,56]

my problem is ... how can i print the a,b,c,d for the coresponding vectors

i.e


i want to print for the above axample ... [3,7,31,56 ] - [a,b,r,c]

and also print
a
b
c
d
When you sort each list, they no longer correspond to a,b,c,r. In your example:
t[0] = a,b,r,c
t[1] = a,b,r,c
t[2] = a,b,c,r

To print a,b,c,r for the first item in the list:
Expand|Select|Wrap|Line Numbers
  1. print 'a = %d\nb = %d\nc = %d\nr = %d' % (t[0][0], t[0][1], t[0][3], t[0][2])
I cannot tell what you are trying to do.
Nov 27 '07 #4

Post your reply

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