Nov-10-2020, 08:54 AM
what you have is list of
It looks like you expect to get a str, (i.e.
You don't need to do so, to remove the duplicates
IPv4Address
objects. When you print a list you get the representation (i.e. __repr__()
) of the individual elements in the list. It looks like you expect to get a str, (i.e.
__str__()
) for each elementimport ipaddress spam = [ipaddress.ip_address('192.168.0.1'), ipaddress.ip_address('192.168.0.2')] eggs = [str(ipadd) for ipadd in spam] print(spam) print(eggs) for ipadd in spam: print(ipadd)
Output:[IPv4Address('192.168.0.1'), IPv4Address('192.168.0.2')]
['192.168.0.1', '192.168.0.2']
192.168.0.1
192.168.0.2
(Nov-09-2020, 03:08 PM)snichols Wrote: so I can remove duplicates in the next step
You don't need to do so, to remove the duplicates
import ipaddress spam = [ipaddress.ip_address('192.168.0.1'), ipaddress.ip_address('192.168.0.2'), ipaddress.ip_address('192.168.0.1')] print(spam) print(list(set(spam)))
Output:[IPv4Address('192.168.0.1'), IPv4Address('192.168.0.2'), IPv4Address('192.168.0.1')]
[IPv4Address('192.168.0.2'), IPv4Address('192.168.0.1')]
Note, set
is unordered collections, so no guarantees about the order
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs