Right split a string into groups of 3

python, python-3.x

Solution

Another way, not sure about efficiency (it'd be better if they were already numbers instead of strings), but is another way of doing it in 2.7+.

for i in map(int, ['123456789', '12345678', '1234567']):
    print i, '->', format(i, ',').split(',')

#123456789 -> ['123', '456', '789']
#12345678 -> ['12', '345', '678']
#1234567 -> ['1', '234', '567']

Problem

What is the most Pythonic way to right split into groups of threes? I've seen this answer https://stackoverflow.com/a/2801117/1461607 but I need it to be right aligned. Preferably a simple efficient one-liner without imports. - '123456789' = ['123','456','789'] - '12345678' = ['12','345','678'] - '1234567' = ['1','234','567']

Original source

Related problems