I don't know if something like this exists already (and I'm not finding the right key words) but if not, it felt like it could be an interesting coding puzzle.
The challenge is, to take an arbitrarily nested list (no more than 2 deep), and display the content in a terminal in 2 dimensions in a 'pretty' manner. Each 'top level' dictionary element should read left - right, and the nested content for each top level index should be displayed vertically in line with its index position.
Example input:
[["A"], ["B", "C"], ["D"], ["E", "F", "G"], ["H"]]
Expected output (option 1):
A B D E H
C F
G
Expected output (option 2):
In this case, 'stacks' should be as close to centralised as possible, so there is a similar amount of content above and below the top level left-to-right content.
E
A B D F H
C G
Example input 2
List contents (for the purpose of this challenge) can be any length, but will always be the same length. e.g.
[["ABC"], ["BCD", "CDE"], ["DEF"], ["EFG", "FGH", "GHI"], ["HIJ"]]
Would also be valid, and should be rendered in similar fashion to example 1:
EFG
ABC BCD DEF EFG HIJ or ABC BCD DEF FGH HIJ
CDE FGH CDE GHI
GHI
Other input considerations (updated in response to comments):
- The indexes of the top level, and nested lists will never be empty.
Criteria:
The solution should take a list of lists (nested 1 deep).
The format of the output is flexible, but it should be clear which elements of the list are distinct at the top level (left to right, in my example separated by spaces) and which elements of the sublists are which (top to bottom, separated vertically on successive lines in my example).
Each item in a sublist inside the list should be printed aligned with each other in the vertical direction.
I don't care about speed/complexity/byte count, so at the highest level the criteria will be considered met by any code that can produces the desired 2D output. The winner is therefore a
popularity-contest
, in that most votes wins (edit: now that answers have started being added the winner will be the answer with the most votes 1 week from today, but new answers would always be welcome).
Bonus points:
How 'pretty' the output is, I'll leave to you. Whether you want it to 'cascade' from the top most character as example 1, or a pseudo-centrally aligned output as example 2. Any other creative solutions are also welcomed.
Code which can handle variable length strings in any position.
I'm particularly interested in Python solutions, but anything goes.