Q:

Split Mac address in a list python

I need to extract last two digits in all Mac address stored in a python list.
['00:00:00:00:00:02',
 '00:00:00:00:00:01',
 '00:00:00:00:00:03',
 '00:00:00:00:00:01',
 '00:00:00:00:00:04',
 '00:00:00:00:00:01']

from this list i need to extract [02,01,03,01,04,01]
or 
is there a method in panda dataframe for this ?

A:

macs = ['00:00:00:00:00:02', '00:00:00:00:00:01', '00:00:00:00:00:03', '00:00:00:00:00:01', '00:00:00:00:00:04', '00:00:00:00:00:01']
short_macs = [x[-2:] for x in macs]

output
['02', '01', '03', '01', '04', '01']

A:

Use rsplit by last separator and seelct last value by position:
L = ['00:00:00:00:00:02', '00:00:00:00:00:01', '00:00:00:00:00:03',
     '00:00:00:00:00:01', '00:00:00:00:00:04', '00:00:00:00:00:01']

out = [x.rsplit(':', 1)[-1] for x in L]
#alternative
#out = [x.split(':')[-1] for x in L]

Or get last 2 values per each value of string by indexing:
out = [x[-2:] for x in L]

print (out)
['02', '01', '03', '01', '04', '01']

