-1

I plan to insert string (colon) in between HEX in Python, i.e;

before: AABBCCDDEEFF112233 after: AA:BB:CC:DD:EE:FF:11:22:33

Can anybody here shed some light on how to achieve it.

Regards,

Al Rizal
  • 31
  • 1
  • 3

1 Answers1

4

The answer to your question is here: Pythonic way to insert every 2 elements in a string

You could also use a step i.e. str[::x] to loop over every 2 characters to achieve this result.

myStr = 'AABBCCDDEEFF112233'
print ':'.join(myStr[i:i+2] for i in range(0, len(myStr), 2))
Community
  • 1
  • 1
Mr. Polywhirl
  • 35,562
  • 12
  • 75
  • 123