# import list of lists list-wise

I produce several times automatically a number of different lists of varying length and structure like:

listA = {{100, 1.7*^10, 2.08*^9}, {105, 1.91*^10, 1.02*^9}, {110,
2.5*^10, 3.08*^9}};
listB = {{126, 27.6, 3.19}, {131, 29.21, 3.2}};
listC = {3.84, 2.9, 5.90, 4.2, 1.3, 0.91, 1.19, 1.5, 2.79, 2.9};


Those I export via: Export["lists.txt", {listA, listB, listC}, "Table"]. I know, that I can import them as a whole Import["lists.txt", "Table"] but I would like to automatically import them list-wise similar to the following fantasy code:

list1 = Import["lists.txt", listA]
list2 = Import["lists.txt", listB]
list3 = Import["lists.txt", listC]


But this doesn't work. And since my lists have varying length, I can't use Part after the import process, since I don't know which length the listA has in the specific case.

Is there an import procedure, which can be used? Do I have to use another export method in order to enable an easier import?

• what is wrong with {list1, list2, list3} = Import["lists.txt", "Table"]? – kglr Jan 26 '19 at 11:46
• you don't need to know the lengths of individual lists to use Part, that is, imp=Import["lists.txt","Table"]; imp[[1]] is just fine to get the first list. Similarly, for imp[[2]], imp[[3]]. – kglr Jan 26 '19 at 11:49
• @kglr Perfect, those are two solutions at once. The first one is exactly, what I searched for. In case you make it an answer, I'll accept it. – Lea Jan 26 '19 at 12:04

You can use

{list1, list2, list3} = Import["lists.txt", "Table"]


Alternatively,

imp = Import["lists.txt", "Table"];
list1 = imp[[1]]
list2 = imp[[2]]


etc.

• there is a problem with this method since in the lists A and B the commas get doubled during import. Independent which of those methods I use, I get for imp[[2]]: {"{126,", "27.6,", "3.19}", "{131,", "29.21,", "3.2}"}. Has this something to do with the "Table"? – Lea Jan 27 '19 at 9:25
• Ah, I found something here mathematica.stackexchange.com/questions/16141/… But for me it is not really satisfying, why does it not work with txt? – Lea Jan 27 '19 at 9:44