| 1 | initial version |
It's easier to iterate over the indices (rather than the values) in the first place:
sage: zz=[(k,z[k]) for k in range(len(z)) if z[k] != 0]
sage: zz
[(0, 5), (2, 5), (4, 10), (5, 13), (6, 14)]
| 2 | No.2 Revision |
It's easier to iterate over the indices (rather than the values) in the first place:
sage: zz=[(k,z[k]) for k in range(len(z)) if z[k] != 0]
sage: zz
[(0, 5), (2, 5), (4, 10), (5, 13), (6, 14)]
Or using a bit cleaner, using enumerate:
sage: zz=[(k,v) for (k,v) in enumerate(z) if v != 0]
sage: zz
[(0, 5), (2, 5), (4, 10), (5, 13), (6, 14)]
| 3 | No.3 Revision |
It's easier to iterate over the indices (rather than the values) in the first place:
sage: zz=[(k,z[k]) for k in range(len(z)) if z[k] != 0]
sage: zz
[(0, 5), (2, 5), (4, 10), (5, 13), (6, 14)]
Or using a bit cleaner, using enumerate:
sage: zz=[(k,v) for (k,v) in enumerate(z) if v != 0]
sage: zz
[(0, 5), (2, 5), (4, 10), (5, 13), (6, 14)]
| 4 | No.4 Revision |
It's easier to iterate over the indices (rather than the values) in the first place:
sage: zz=[(k,z[k]) zz = [(k, z[k]) for k in range(len(z)) if z[k] != 0]
sage: zz
[(0, 5), (2, 5), (4, 10), (5, 13), (6, 14)]
Or a bit cleaner, using enumerate:
sage: zz=[(k,v) zz = [(k, v) for (k,v) k, v in enumerate(z) if v != 0]
sage: zz
[(0, 5), (2, 5), (4, 10), (5, 13), (6, 14)]
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.