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:f
You can use str.rsplit() to split from the right:
str.rsplit()
>>> ipaddress = 'fe80::e590:1001:7d11:1c7e' >>> ipaddress.rsplit(':', 2) # splits at most 2 times from the right ['fe80::e590:1001', '7d11', '1c7e']
This avoids the unnecessary splitting of the first part of the address.