1
$\begingroup$

How to insert multiple elements in a list?

list={1,2,3,4,5,6,7,8,9}

Output: {"X" 1,"X" 2,"X" 3,"X" 4,"X" 5,"X" 6,"X" 7,"X" 8,"X" 9}

I have the listand would like to insert a string X into each element in the list. How do I do that?

$\endgroup$
  • $\begingroup$ How about "X" # & /@ list $\endgroup$ – PatrickS Dec 2 '15 at 12:05
  • 2
    $\begingroup$ Sorry for nitpicking: HoldForm /@ {1, 2, 3, 4, 5, 6, 7, 8, 9} "X" $\endgroup$ – Kuba Dec 2 '15 at 12:05
  • $\begingroup$ Just to add one more way: list /. x_Integer -> {"X", x} // Flatten ?? $\endgroup$ – Alexei Boulbitch Dec 2 '15 at 12:16
  • $\begingroup$ Dear NewTester4201, are missing comas intentional? $\endgroup$ – Kuba Dec 2 '15 at 13:02
  • 1
    $\begingroup$ Is it a good example of 'easy found in doc'? $\endgroup$ – garej Dec 2 '15 at 13:22

Browse other questions tagged or ask your own question.