Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Placeholder:
- def __repr__(self):
- return " "
- empty = Placeholder()
- def align_nicely(a,b):
- maxlen = lambda seq: max(len(subseq) for subseq in seq)
- padded = lambda seq, size: seq + [empty]*(size-len(seq))
- maxwidths = [maxlen(a), maxlen(b)]
- results = []
- for item1, item2 in zip(a,b):
- results.append(padded(item1, maxwidths[0]) + padded(item2, maxwidths[1]))
- for row in results:
- print(row)
- a = [[1, 2, 3], [1, 2], [1, 2, 3, 4], [1, 2, 3, 4, 5]]
- b = [[1, 2, 3], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3]]
- align_nicely(a,b)
- """result:
- [1, 2, 3, , , 1, 2, 3, ]
- [1, 2, , , , 1, 2, 3, ]
- [1, 2, 3, 4, , 1, 2, 3, 4]
- [1, 2, 3, 4, 5, 1, 2, 3, ]
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement