# If I have numbered elements, I there a simple way to put them in a list? [duplicate]

I've defined manually 32 elements as w1, w2, w3,..., w32. Is there a simple way to put them in a list rather that write B={w1, w2, ..., w32}? Like a list making function that understands some indexes? (here, each wi is itself a list, i=1,...,32 )

## marked as duplicate by rhermans, Community♦Sep 27 '17 at 15:41

• Use indexed variables. B = Array[w, 32] – Bob Hanlon Sep 27 '17 at 15:03
• @BobHanlon So I have to relabel the elements as w[1], w[2], etc. ? – Filburt Sep 27 '17 at 15:15
• you could use Table[Symbol["w" <> ToString[i]], {i, 1, 32}] – RMMA Sep 27 '17 at 15:23
• Yes. Use Edit | Find | Replace All – Bob Hanlon Sep 27 '17 at 15:58

You can use Names[x] to get all the symbols that match the string or pattern argument.

If you want the names

B = Names["w*"]


or if you want the content you can use Symbol or ToExpression

B = ToExpression /@ Names["w*"]


But ultimately the answer is to use indexed variables as noted by Bob Hanlon.

Read the documentation and this Q&A that comments of the use of string-based variables names, as the comment by RMMA.