I am looking for a more elegant solution to formatting a MAC address with colons. I am using Python 3.2. A fancy list comprehension perhaps?
s=\"\"
h=\"0023
The easiest solution here is just to use str.join()
>>> ":".join(str_grouper(2, "00233a990c21"))
'00:23:3a:99:0c:21'
Here using a modified version of the grouper()
recipe from the itertools
docs:
def str_grouper(n, iterable):
args = [iter(iterable)] * n
for part in zip(*args): #itertools.izip in 2.x for efficiency.
yield "".join(part)