4 ms·
itertools has functions that make that sort of nesting unnecessary (and some would say make the code clearer), eg: import itertools as it [f(a, b) for
by kbp 8y ago
itertools has functions that make that sort of nesting unnecessary (and some would say make the code clearer), eg:
import itertools as it
[f(a, b) for a, b in it.product(some_list, some_list) if a is not b]
- deleted 8y ago[deleted]
- kbp 8y agoOh, or more directly: [f(a, b) for a, b in it.permutations(some_list, r=2)] And then you could also use itertools.starmap instead of using a comprehension at all, if you wanted.