1 | initial version |
No need for L2. With your definitions :
sage: list(map(F, L0, L1))
[0, 1, 2, 3]
From map?
map(func, >>*<<iterables) --=""> map object
Make an iterator that computes the function using arguments from each
of the iterables. Stops when the shortest iterable is exhausted.
Learn Python !
2 | No.2 Revision |
No need for L2. With your definitions Two possibilities (among others I suppose...) :
sage: list(map(F, L0, L1))
[F(u[0], u[1]) for u in L2]
[0, -3, -6, -9, -2, 1, 1, -2, -8, -1, 2, 5, -18, -7, 0, 3]
sage: list(map(lambda u:F(*u), L2))
[0, -3, -6, -9, -2, 1, 1, -2, -8, -1, 2, 5, -18, -7, 0, 3]`
Building `L2 isn't necessary :
sage: [F(*u) for u in Set(L0).cartesian_product(Set(L1))]
[0, -2, -8, -18, -3, 1, -1, -7, -6, 1, 2, 0, -9, -2, 5, 3]
From I suppose that the
standard Pythonlibrary offers other possibilities...map?itertools
map(func, >>*<<iterables) --=""> map object
Make an iterator that computes the function using arguments from each
of the iterables. Stops when the shortest iterable is exhausted.
Learn Python !
HTH,
3 | No.3 Revision |
Two possibilities (among others I suppose...) :
sage: [F(u[0], u[1]) for u in L2]
[0, -3, -6, -9, -2, 1, 1, -2, -8, -1, 2, 5, -18, -7, 0, 3]
sage: list(map(lambda u:F(*u), L2))
[0, -3, -6, -9, -2, 1, 1, -2, -8, -1, 2, 5, -18, -7, 0, 3]`
Building `L2 isn't necessary :
sage: [F(*u) for u in Set(L0).cartesian_product(Set(L1))]
[0, -2, -8, -18, -3, 1, -1, -7, -6, 1, 2, 0, -9, -2, 5, 3]
I suppose that the itertools
standard Pythonlibrary offers other possibilities...
Personally, I'd dispense with L2 and would simply do :
sage: table([[F(u, v) for v in L1] for u in L0], header_column=["F"]+L0, header_row=L1)
F | 0 1 2 3
+---+----+----+----+-----+
0 | 0 -2 -8 -18
1 | -3 1 -1 -7
2 | -6 1 2 0
3 | -9 -2 5 3
Learn Python !
HTH,
4 | No.4 Revision |
Two possibilities (among others I suppose...) :
sage: [F(u[0], u[1]) for u in L2]
[0, -3, -6, -9, -2, 1, 1, -2, -8, -1, 2, 5, -18, -7, 0, 3]
You can pass a list (or other iterable) of arguments via indirection :
sage: [F(*u) for u in L2]
[0, -3, -6, -9, -2, 1, 1, -2, -8, -1, 2, 5, -18, -7, 0, 3]
or equivalently (see map?
) :
sage: list(map(lambda u:F(*u), L2))
[0, -3, -6, -9, -2, 1, 1, -2, -8, -1, 2, 5, -18, -7, 0, 3]`
Building `L2 isn't necessary :
sage: [F(*u) for u in Set(L0).cartesian_product(Set(L1))]
[0, -2, -8, -18, -3, 1, -1, -7, -6, 1, 2, 0, -9, -2, 5, 3]
I suppose that the itertools
standard Pythonlibrary offers other possibilities...
Personally, I'd dispense with L2 and would simply do :
sage: table([[F(u, v) for v in L1] for u in L0], header_column=["F"]+L0, header_row=L1)
F | 0 1 2 3
+---+----+----+----+-----+
0 | 0 -2 -8 -18
1 | -3 1 -1 -7
2 | -6 1 2 0
3 | -9 -2 5 3
Learn Python !
HTH,