bearophile_hugs@eml.cc
| https://issues.dlang.org/show_bug.cgi?id=9593
--- Comment #2 from bearophile_hugs@eml.cc ---
Sometimes the output is so much noisy that it's unreadable:
void main() {
import std.stdio: writeln;
import std.algorithm: cartesianProduct;
import std.range: enumerate;
auto a = [10, 20];
cartesianProduct(a.enumerate, a.enumerate)
.writeln;
}
Output:
[Tuple!(Tuple!(uint, "index", int, "value"), Tuple!(uint, "index", int,
"value"))(Tuple!(uint, "index", int, "value")(0, 10), Tuple!(uint, "index",
int, "value")(0, 10)), Tuple!(Tuple!(uint, "index", int, "value"), Tuple!(uint,
"index", int, "value"))(Tuple!(uint, "index", int, "value")(0, 10),
Tuple!(uint, "index", int, "value")(1, 20)), Tuple!(Tuple!(uint, "index", int,
"value"), Tuple!(uint, "index", int, "value"))(Tuple!(uint, "index", int,
"value")(1, 20), Tuple!(uint, "index", int, "value")(0, 10)),
Tuple!(Tuple!(uint, "index", int, "value"), Tuple!(uint, "index", int,
"value"))(Tuple!(uint, "index", int, "value")(1, 20), Tuple!(uint, "index",
int, "value")(1, 20))]
A similar Python program:
from itertools import product
a = [10, 20]
print list(product(enumerate(a), enumerate(a)))
Prints a readable output:
[((0, 10), (0, 10)), ((0, 10), (1, 20)), ((1, 20), (0, 10)), ((1, 20), (1,
20))]
--
|