Problem with python in using .join

0

I need to print a MAC address, with ':' tab, but I can only print the address with the tab for each string in the string, with the MAC address separating every 2 boxes.

    
asked by anonymous 20.03.2018 / 14:53

2 answers

0

If you are going to use .join then this solution will answer you:

>>> ':'.join([addr[x-2:x] for x in range(2, len(addr)+2,2)])
'0a:1b:2c:3d:4e:5f'
    
22.03.2018 / 04:39
0

If it's just for screen printing, you can try a simpler solution:

>>> addr='0a1b2c3d4e5f'
>>> '{0}{1}:{2}{3}:{4}{5}:{6}{7}:{8}{9}:{10}{11}'.format(*addr)
'0a:1b:2c:3d:4e:5f'
    
22.03.2018 / 03:54