Code: Alles auswählen
c = 8
a = [range(i, c + i) for i in range(0, 20, 2)]
print 'a:\n', a
b = [[] for i in range(c)]
for x in a:
for y, z in zip(b, x):
y.append(z)
print 'b:\n', b
Danke
HWK
Code: Alles auswählen
c = 8
a = [range(i, c + i) for i in range(0, 20, 2)]
print 'a:\n', a
b = [[] for i in range(c)]
for x in a:
for y, z in zip(b, x):
y.append(z)
print 'b:\n', b
Code: Alles auswählen
In [13]: a
Out[13]:
[[0, 1, 2, 3, 4, 5, 6, 7],
[2, 3, 4, 5, 6, 7, 8, 9],
[4, 5, 6, 7, 8, 9, 10, 11],
[6, 7, 8, 9, 10, 11, 12, 13],
[8, 9, 10, 11, 12, 13, 14, 15],
[10, 11, 12, 13, 14, 15, 16, 17],
[12, 13, 14, 15, 16, 17, 18, 19],
[14, 15, 16, 17, 18, 19, 20, 21],
[16, 17, 18, 19, 20, 21, 22, 23],
[18, 19, 20, 21, 22, 23, 24, 25]]
In [14]: map(list, zip(*a))
Out[14]:
[[0, 2, 4, 6, 8, 10, 12, 14, 16, 18],
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19],
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
[3, 5, 7, 9, 11, 13, 15, 17, 19, 21],
[4, 6, 8, 10, 12, 14, 16, 18, 20, 22],
[5, 7, 9, 11, 13, 15, 17, 19, 21, 23],
[6, 8, 10, 12, 14, 16, 18, 20, 22, 24],
[7, 9, 11, 13, 15, 17, 19, 21, 23, 25]]
Code: Alles auswählen
reduce(lambda x, y: x or bool(y), liste, False)
Code: Alles auswählen
result = False
for y in liste:
result = result or bool(y)
Code: Alles auswählen
def any(itarable):
return True in (bool(item) for item in iterable)
Hallo,HWK hat geschrieben:Gibt es evtl. auch eine andere, elegante Lösung für folgende Funktion in der Art 'if_any'?Code: Alles auswählen
reduce(lambda x, y: x or bool(y), liste, False)