If c = '32486784298'
,
then '{0}{1}{2}.{3}{4}{5}.{6}{7}{8}-{9}{10}'.format(*c)
prints '324.867.842-98'
.
Is there a simplest way to do this? (with no def please)
If c = '32486784298'
,
then '{0}{1}{2}.{3}{4}{5}.{6}{7}{8}-{9}{10}'.format(*c)
prints '324.867.842-98'
.
Is there a simplest way to do this? (with no def please)
In the latest versions of Python you can omit number in string-format placeholders:
>>> '{}{}{}.{}{}{}.{}{}{}-{}{}'.format(*c)
'324.867.842-98'
It works in Python 2.7.
''.join([c[0:3],'.',c[3:6],'.',c[6:9],'-',c[9:11])
OR
c[0:3]+'.'+c[3:6]+'.'+c[6:9]+'-'+c[9:11]
'%s.%s.%s-%s' % tuple(c[i:j] for i, j in ((0, 3), (3, 6), (6, 9), (9, 11)))