# How to convert a list of names and values into a series of expressions [duplicate]

I had an Excel spreadsheet with a list of symbols names in the first column and a list of values in the second column. I imported it. Working with the resulting expression, I now have (in Mathematica) a list of names and a list of corresponding values.

names[[1 ;; 44]]

values[[1 ;; 44]]
{6.02214*10^23, 1.66054*10^-27, 8.31446


What I want is a package with "assignement statements."

avogadro=6.23
boltzman=59


etc. I have no idea how to convert a pair of lists into a series of expressions. In fact, I don't know what functions to look up in the documentation. How to get my constants into a package?

• I think it is covered by the generic topic I've linked, let me know if you disagree with closing.
– Kuba
Aug 7, 2018 at 7:29

You can try this:

MapThread[
ToExpression["Set[" <> #1 <> "," <> ToString[#2] <> "]"] &,
{names, values}
]

• Or ToExpression@StringTemplate["="][##] &
– Kuba
Aug 7, 2018 at 7:39

Also:

MapThread[Set, {Symbol /@ names, values}] (* or *)
Set @@@ Transpose[{Symbol /@ names, values}]

• OK, MapThread[ ToExpression["Set[" <> #1 <> "," <> ToString[#2] <> "]"] &, {namesd, valuesd}] worked, but how do I make the symbols permanent? It is my experience that symbols in Mathematica just go away after a few days. It was a big deal creating the lists of names and symbols. I don't want to have to repeat it every day. Aug 7, 2018 at 7:07
• @GeneNaden Unless you save them they will go away, take a look at this topic and other topics linked there: mathematica.stackexchange.com/q/121/5478 As well as documentation for Save/DumpSave etc.
– Kuba
Aug 7, 2018 at 7:36
• Yeah, I used Save command and it created a file with the lists in it, so that solved it. Aug 8, 2018 at 14:50