having trouble with mathematica using nested lists. I want to save a list like this:


So, the nested components do not have an identical dimension. However, whenever I save the file (as csv or xls) and reimport it seems that the inner lists (like l1[[1,2]] is transformed into a string which I would like to bypass somehow.

  • 2
    $\begingroup$ If your aim is to re-import into Mathematica, use a format that can store arbitrary Mathematica expressions. This includes the "WDX", "Package" and "MX" Export formats. Some prefer using Compress and exporting the result as a "String". Note that "MX" is not cross-version-compatible and not cross platform before v10. $\endgroup$ – Szabolcs Apr 15 '15 at 0:05
  • $\begingroup$ Related: (2008) $\endgroup$ – Mr.Wizard Apr 15 '15 at 1:28
  • 1
    $\begingroup$ "CSV stores tabular data." More specifically, it stores ragged-right 2D arrays. XLS stores a set of sparse 2D arrays and some metadata. They are simply not capable of encoding nested lists of arbitrary depth. $\endgroup$ – 2012rcampion Apr 15 '15 at 3:14
  • $\begingroup$ thanks a lot for the clarification with the *.csv and *.xls-files. The MX-package works fine, too! $\endgroup$ – noclue11 Apr 15 '15 at 13:38


l1 = {{a1, {a, b, c, d, e}}, {a2, {f, g, h, i}}};

one exports using


and imports next with


If you don't SetDirectory, it will go to home directory and be then imported from there also.

See also this answer.

  • $\begingroup$ Does that really resolve the issue here? Essentially, I am not able to access the parts of my nested lists because some are simply converted to a string? $\endgroup$ – noclue11 Apr 14 '15 at 16:22
  • $\begingroup$ I updated the answer providing a working example. $\endgroup$ – corey979 Apr 14 '15 at 23:06

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.