7
$\begingroup$

Here's my problem when doing my codes.

I need an output similar to {{p->1},{p->2},{p->3},{p->4}},where p is a generic variable. How can I achieve such results?

If anyone knows how, plz help me. Thank you!

$\endgroup$
12
$\begingroup$
{p -> #} & /@ Range[4]

{{p -> 1}, {p -> 2}, {p -> 3}, {p -> 4}}

Also

Table[{p -> i}, {i, 4}]
Array[{p -> #} &, 4]
Range[4] /. x_Integer :> {p -> x}
List /@ Thread[p -> Range[4]]

all give

{{p -> 1}, {p -> 2}, {p -> 3}, {p -> 4}}

$\endgroup$
  • $\begingroup$ Thank you three thousand times! $\endgroup$ – Robin_Lyn Jul 20 at 13:37
  • $\begingroup$ @Robin, you are welcome.. $\endgroup$ – kglr Jul 20 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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