Reputation: 875
How can I combine this:
ipaddresses = [ipadr['ip'] for ipadr in hosts]
for ipadr in ipaddresses:
ips = '.'.join(str(i) for i in ipadr)
Into One declaration with 2 list comprehensions? I just don't get it. Thanks
ipaddresses will print something like this:
[[10, 10, 10, 10], [10, 20, 20, 20]]
Upvotes: 2
Views: 140
Reputation: 799430
You only need 1 LC, not 2.
['.'.join(str(octet) for octet in addr['ip']) for addr in hosts]
Upvotes: 7