3
$\begingroup$

Given:

Map[f, {{a, f, h, m, n, k},{a, b}, {z, d, f, h, k}, {c, d, e}, {c, p}}]

I like to have a list of ordered functions as follows:

{a = f[b], c = f[p], c = f[d, e], z = f[d, f, h, k], a = f[f, h, m, n, k]}
$\endgroup$
2
  • $\begingroup$ What do you mean by "functions"? In your result, a and c are defined twice (so the latter evaluations will replace the former ones), so it seems like you don't actually want to define these as functions, do you? $\endgroup$
    – lericr
    Commented Nov 5, 2023 at 23:26
  • $\begingroup$ @lericr: I just want to translate the list to a list of functional forms like the one given as an answer below. $\endgroup$ Commented Nov 6, 2023 at 0:03

2 Answers 2

7
$\begingroup$
Clear["Global`*"];

list = {{a, f, h, m, n, k}, {a, b}, {z, d, f, h, k}, {c, d, e}, {c, p}};

HoldForm[#1 = f[##2]] & @@@ Sort[list]

enter image description here

$\endgroup$
4
$\begingroup$

or use named function.

ff[{a_, b__}] := HoldForm[a = f[b]];

{{a, f, h, m, n, k},{a, b}, {z, d, f, h, k}, {c, d, e}, {c, p}} //
Sort //
Map[ff]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.