wagner-felix
wagner-felix

Reputation: 875

Python List comprehension one declaration and 2 Comprehensions

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

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799430

You only need 1 LC, not 2.

['.'.join(str(octet) for octet in addr['ip']) for addr in hosts]

Upvotes: 7

Related Questions