444,199 Members | 1,191 Online 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 a = [3, 2, 1] b = [7, 5, 3] c = [56, 242, 4] r = [31, 146, 124]   t = zip(a, b, c, r) print t # [(31, 7, 56, 3), (2, 5, 242, 146), (1, 3, 4, 124)] for i, intTuple in enumerate(t):     t[i] = sorted(intTuple) print t # [[3,  7, 31,56], [2, 5, 146, 242], [1, 3, 4, 124]]   print t[:1]   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
3 Replies

 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 a = [3, 2, 1] b = [7, 5, 3] c = [56, 242, 4] r = [31, 146, 124]   t = zip(a, b, c, r) print t # [(31, 7, 56, 3), (2, 5, 242, 146), (1, 3, 4, 124)] for i, intTuple in enumerate(t):     t[i] = sorted(intTuple) print t # [[3,  7, 31,56], [2, 5, 146, 242], [1, 3, 4, 124]]   print t[:1]   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

 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 a = [3, 2, 1] b = [7, 5, 3] c = [56, 242, 4] r = [31, 146, 124]   t = zip(a, b, c, r) print t # [(31, 7, 56, 3), (2, 5, 242, 146), (1, 3, 4, 124)] for i, intTuple in enumerate(t):     t[i] = sorted(intTuple) print t # [[3,  7, 31,56], [2, 5, 146, 242], [1, 3, 4, 124]]   print t[:1]   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 = a,b,r,c t = a,b,r,c t = a,b,c,r To print a,b,c,r for the first item in the list: Expand|Select|Wrap|Line Numbers print 'a = %d\nb = %d\nc = %d\nr = %d' % (t, t, t, t) I cannot tell what you are trying to do. Nov 27 '07 #4 