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>

<p>Would you be able to base it on code like this?</p>

<pre><code>from urllib.parse import urlparse

parseResult = urlparse('http://www.fake.ca/185')
print ( parseResult )
</code></pre>

<p>parseResult is a structure with elements that are revealed in the output of the print statement.</p>

<p>ParseResult(scheme='http', netloc='www.fake.ca', path='/185', params='', query='', fragment='')</p>

python split idiomatic