I know that the topic of smoothing a nested list has been discussed in detail before, but I think that my task is a little different, and I could not find any information.
I am writing a scraper, and as an output I get a nested list. Top-level list items must be rows for data in the form of spreadsheets. However, since nested lists often have different lengths, I need to expand them before aligning the list.
Here is an example. I have
[ [ "id1", [["x", "y", "z"], [1, 2]], ["a", "b", "c"]], [ "id2", [["x", "y", "z"], [1, 2, 3]], ["a", "b"]], [ "id3", [["x", "y"], [1, 2, 3]], ["a", "b", "c", ""]] ]
The conclusion that I ultimately want is
[[ "id1", "x", "y", z, 1, 2, "", "a", "b", "c", ""], [ "id2", "x", "y", z, 1, 2, 3, "a", "b", "", ""], [ "id3", "x", "y", "", 1, 2, 3, "a", "b", "c", ""]]
However an interim list like this
[ [ "id1", [["x", "y", "z"], [1, 2, ""]], ["a", "b", "c", ""]], [ "id2", [["x", "y", "z"], [1, 2, 3]], ["a", "b", "", ""]], [ "id3", [["x", "y", ""], [1, 2, 3]], ["a", "b", "c", ""]] ]
which I can then just smooth out, will also be fine.
Top-level list items (rows) are created at each iteration and added to the complete list. I think in the end itβs easier to convert a complete list?
The structure in which the elements are nested must be the same, however I cannot be sure of that. I think I have a problem if the structure is where it looks.
[ [ "id1", [[x, y, z], [1, 2]], ["a", "b", "c"]], [ "id2", [[x, y, z], [1, 2, 3]], ["bla"], ["a", "b"]], [ "id3", [[x, y], [1, 2, 3]], ["a", "b", "c", ""]] ]
which should become
[[ "id1", x, y, z, 1, 2, "", "", "a", "b", "c", ""], [ "id2", x, y, z, 1, 2, 3, "bla", "a", "b", "", ""], [ "id3", x, y, "", 1, 2, 3, "", "a", "b", "c", ""]]
Thanks for any comments, and please excuse me if this is trivial, I'm pretty new to Python.