putting a string in Mac Address form
Alex Martelli
aleaxit at yahoo.com
Sun Oct 30 21:10:29 EST 2005
kyle.tk <kyle.tk at gmail.com> wrote:
...
> new_mac = ''
> c = 0
> while len(new_mac) < 16:
> new_mac += mac[c:c+2] + ':'
> c=c+2
> return new_mac[:-1].upper()
...
> The part I think is bad is the while loop part. Could it be better?
What about replacing this whole block with, say...:
return ':'.join(mac[c:c+2] for c in range(0, 12, 2)).upper()
(as you did already check that len(mac) is 12...)
Alex
More information about the Python-list
mailing list