4 ms·
[(x[i],x[j]) for i in range(len(x)) for j in range(i+1, len(x))] His problem is not with functional programming (i.e. avoiding state mutations). It is that he
by fab13n 15y ago
[(x[i],x[j]) for i in range(len(x)) for j in range(i+1, len(x))]
His problem is not with functional programming (i.e. avoiding state mutations). It is that he tries to do inductive definitions and functors in a language whose syntax is extremely unsupportive. In OCaml that would be (untested code):
let rec pairs = function
| a :: b -> List.map (fun x -> (a, x)) b @ (pairs b)
| [] -> []