In Python there is a a compact syntax for creating variables that refer to the various list elements.

>>> somelist = [’book.tex’, ’book.log’, ’book.pdf’]
>>> texfile, logfile, pdf = somelist
>>> texfile
>>> logfile
>>> pdf

Of course the number of variables on the left-hand side must match the number of elements in the list. The only relevant I can think in Mathematica is MapThread (or Thread).

In[4]:= somelist = {"book.tex", "book.log", "book.pdf"};
MapThread[Set, {{texfile, logfile, pdf}, somelist}]

Out[5]= {"book.tex", "book.log", "book.pdf"}

Is there anything else similar in Mathematica? Thank you very much.


1 Answer 1


Yeah, you can do destructuring assignments:

someList = {"book.tex", "book.log", "book.pdf"};

{texFile, logFile, pdf} = someList;

(* "book.tex" *)

(* "book.pdf *)

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.