--file: Unzip.txt-- --file start-- ---code start--- def unzip(l,*jj): '''Returns one or more of the elements in the tuples of l that were zipped together. ''' # # This code will unzip lists which have been zipped together. # If you created a zipped list, l=zip(a,b,c), you can use unzip # to extract one or more of the lists: # a,b,c=unzip(l) # b=unzip(l,1) # a,c=unzip(0,2) # # Christopher P. Smith 7/13/2001 # if jj==(): jj=range(len(l[0])) rl = [[li[j] for li in l] for j in jj] # a list of lists if len(rl)==1: rl=rl[0] #convert list of 1 list to a list return rl ---code end--- ---example start--- a=[1,2,3] b=[4,5,6] c=[7,8,9] l=zip(a,b,c) x,y,z= unzip(l) # get them all: x=[1,2,3], y=[4,5,6], z=[7,8,9] y=unzip(l,1) # get the 1th one: y as above x,z=unzip(l,0,2)# get the 0th and 2th ones: x and z as above ---example end--- --file end-- --comment start-- This code will unzip lists which have been zipped together. If you created a zipped list, l=zip(a,b,c), you can use unzip to extract one or more of the lists: a,b,c=unzip(l) b=unzip(l,1) a,c=unzip(0,2) --comment end--