Pythonic way to split string then split again on result?
<p>Is there a more pythonic way to do this</p>

<pre><code>def parse_address(hostname, addresses):
    netmask=''
    for address in addresses:
        if hostname in address:
            _hostname, _netmask = address.strip().split('/')
            hostname = _hostname.split()[-1]
            netmask = '/' + _netmask.split()[0]
            break

    return netmask
</code></pre>

<h3>Test case</h3>

<p>If you do TDD</p>

<pre><code>def test_parse_netmask(self):
        hostname = '127.0.0.1'

        stdout = [
            "1: lo    inet 127.0.0.1/8 scope host lo\       valid_lft forever preferred_lft forever",
            "3: wlp4s0    inet 192.168.2.133/24 brd 192.168.2.255 scope global dynamic wlp4s0\       valid_lft 58984sec preferred_lft 58984sec",
            "4: docker0    inet 172.17.0.1/16 scope global docker0\       valid_lft forever preferred_lft forever",
            "5: br-a49026d1a341    inet 172.18.0.1/16 scope global br-a49026d1a341\       valid_lft forever preferred_lft forever",
            "6: br-d26f2005f732    inet 172.19.0.1/16 scope global br-d26f2005f732\       valid_lft forever preferred_lft forever",
        ]

        netmask = scanner.parse_address(hostname, stdout)

        self.assertEqual(netmask, '/8')
</code></pre>

<pre><code>def x(hostname,addresses):
    import re 
    for address in addresses:
        result = re.search(hostname+r"/\d", address)
        if result:
            return result.group(0).split(hostname)[1]
</code></pre>

<p>Don't know if it's more 'Pythonic' but I would do it this way. It's readable to others, yet it's short enough to not drag on the function.</p>

python split idiomatic