Extract Last Two Fields From Split
I want to extract last two field values from a variable of varying length. For example, consider the three values below: fe80::e590:1001:7d11:1c7e ff02::1:ff1f:fb6 fe80::7cbe:e61
Solution 1:
If s
is the string containing the IPv6 address, use
s.split(":")[-2:]
to get the last two components. The split()
method will return a list of all components, and the [-2:]
will slice this list to return only the last two elements.
Post a Comment for "Extract Last Two Fields From Split"