Nov-10-2020, 09:22 AM
From buran's answer one could easily conclude that in order to get sorted unique ip addresses one should first uniquify and then sort. As
from Python 3.9 there is also IPv4Address.__format__(fmt) for converting into other types (string, binary, hex).
Similarly to
sorted()
takes any iterable and returns list one can just apply it to set and get sorted list:>>> import ipaddress >>> spam = [ipaddress.ip_address('192.168.0.1'), ipaddress.ip_address('192.168.0.2'), ipaddress.ip_address('192.168.0.1')] >>> sorted(set(spam)) [IPv4Address('192.168.0.1'), IPv4Address('192.168.0.2')]As far as conversion goes:
from Python 3.9 there is also IPv4Address.__format__(fmt) for converting into other types (string, binary, hex).
Similarly to
str()
there is also possibility to convert to integer with int()
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.