0

i want to use a function like "{}".format (variable)
so i can transform a string like: "

A1B345FS

" And i want to have something like: "

A1:B3:45:FS

" i am not able to use a while or a for.

Can i use .join (variable) ????

  • possible duplicate of [Iterating over every two elements in a list](http://stackoverflow.com/questions/5389507/iterating-over-every-two-elements-in-a-list) – jonrsharpe Apr 30 '15 at 11:24
  • Something like http://stackoverflow.com/questions/9475241/split-python-string-every-nth-character? – user1267259 Apr 30 '15 at 13:25
  • No, i need to insert the " : " every 2 characters and without the use of a while or a for cicle. I allready have a for cicle to do this, but i wounder if there is some clean way. i = 0 resul = "" for r in mac: i += 1 resul += r if i == 2: resul += ":" i = 0 – Pedro Mendes Apr 30 '15 at 14:18

1 Answers1

0

I think the following code solves the problem.

import re
s = "A1B345FS"
s2=re.findall('..',s)
s3=":".join(s2)

print(s3)