If I was writing this, however, I would probably do it in just a couple of lines, as you know exactly how the input and output strings are going to be formatted: def mac_conv(mac, sep='-'):
You can actually eliminate that usage of the variable all together: #join groups into a single MAC I would also avoid reusing variables, especially if its a function argument ( mac). #Open file with MAC addresses and convert them Return '.'.join(''.join(group) for group in groups)įirst of all, you should be using return rather than print to get a value out of a function, otherwise you'll have problems when you try to expand the program. This can result in: def mac_conv(mac, sep='-'): Other than the above function, you don't need to use f.readlines() you can just use f.
I'd then join the last three lines into one.Īs return and '.'.join are easy to understand in a single one-liner.