bskinn / pent

pent Extracts Numerical Text -- Mini-language driven parser for structured numerical data in text
MIT License
20 stars 3 forks source link

Implement left-pad and right-pad for non-rectangular 2D data #25

Open bskinn opened 6 years ago

bskinn commented 6 years ago

E.g., upper- or lower-triangular matrices.

Find the max row width, then pad either side (pad.extend(data) or data.extend(pad)) with an appropriate fill value. Probably default to '' for any/str types, and to 0 for numeric types, with a fill_value= argument available to override.

More pythonic construction for right-pad is probably:

list(itt.chain(l, itt.repeat(fill_value, fill_times))

Mirror-image for left-pad

bskinn commented 6 years ago

Changed to 'maybe' since it may or may not be general enough a need to be worth implementing here. May be sensible to leave most (all?) post-processing to the user.

OTOH, helper functions for very common situations would probably be appreciated.