MCPcopy Create free account
hub / github.com/ActiveState/code / rezip

Function rezip

recipes/Python/278257_List_Tools/recipe-278257.py:133–148  ·  view source on GitHub ↗

d = [[1, 5, 8, 3], [2, 2, 3, 9], [3, 2, 4, 6]] rezip(d): [(1, 2, 3), (5, 2, 2), (8, 3, 4), (3, 9, 6)] If a =[1, 5, 8], b=[2, 2, 3], c=[3, 2, 4] then it's eazy to: zip(a,b,c) = [(1, 2, 3), (5, 2, 2), (8, 3, 4)] But it's hard for d = [[1, 5, 8], [2, 2, 3], [3, 2, 4]]

(aList)

Source from the content-addressed store, hash-verified

131
132#========================================================================
133def rezip(aList):
134 ''' d = [[1, 5, 8, 3], [2, 2, 3, 9], [3, 2, 4, 6]]
135 rezip(d):
136 [(1, 2, 3), (5, 2, 2), (8, 3, 4), (3, 9, 6)]
137
138 If a =[1, 5, 8], b=[2, 2, 3], c=[3, 2, 4]
139 then it's eazy to: zip(a,b,c) = [(1, 2, 3), (5, 2, 2), (8, 3, 4)]
140
141 But it's hard for d = [[1, 5, 8], [2, 2, 3], [3, 2, 4]]
142 '''
143
144 tmp = [ [] for x in range(len(aList[0])) ]
145 for i in range(len(aList[0])):
146 for j in range(len(aList)):
147 tmp[i].append(aList[j][i])
148 return tmp
149
150#========================================================================
151def sumInList(complexList):

Callers 2

sumInListFunction · 0.70
avgInListFunction · 0.70

Calls 2

rangeFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected