python - Right split a string into groups of 3 -


what pythonic way right split groups of threes? i've seen answer https://stackoverflow.com/a/2801117/1461607 need right aligned. preferably simple efficient one-liner without imports.

  • '123456789' = ['123','456','789']
  • '12345678' = ['12','345','678']
  • '1234567' = ['1','234','567']

another way, not sure efficiency (it'd better if numbers instead of strings), way of doing in 2.7+.

for in map(int, ['123456789', '12345678', '1234567']):     print i, '->', format(i, ',').split(',')  #123456789 -> ['123', '456', '789'] #12345678 -> ['12', '345', '678'] #1234567 -> ['1', '234', '567'] 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -