I don't think there is a direct way to do this, since you need to know the position of the decimal point in all numbers before you start typing them. (I just looked at the Caramiriel link and some links from this page, but I could not find anything particularly applicable to this case).
So it looks like you need to do some string-based checking and manipulate the numbers in the list. For instance,
def dot_aligned(seq): snums = [str(n) for n in seq] dots = [s.find('.') for s in snums] m = max(dots) return [' '*(m - d) + s for s, d in zip(snums, dots)] nums = [4.8, 49.723, 456.781, -72.18] for s in dot_aligned(nums): print(s)
Output
4.8 49.723 456.781 -72.18
If you want to handle a float list with some simple int , then this approach becomes a bit messy.
def dot_aligned(seq): snums = [str(n) for n in seq] dots = [] for s in snums: p = s.find('.') if p == -1: p = len(s) dots.append(p) m = max(dots) return [' '*(m - d) + s for s, d in zip(snums, dots)] nums = [4.8, 49.723, 456.781, -72.18, 5, 13] for s in dot_aligned(nums): print(s)
Output
4.8 49.723 456.781 -72.18 5 13
Update
As Mark Ransom notes in the comments, we can simplify int processing with .split :
def dot_aligned(seq): snums = [str(n) for n in seq] dots = [len(s.split('.', 1)[0]) for s in snums] m = max(dots) return [' '*(m - d) + s for s, d in zip(snums, dots)]