Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
crunching ip addresses
#5
I often use the fact, that a dict is a set without values, but since Python 3.6 the order is preserved.
So using list(dict.fromkey(iterable)) will keep the order from the original iterable, but will remove duplicates.

from ipaddress import ip_address

spam = [ip_address('192.168.0.1'), ip_address('192.168.0.2'), ip_address('192.168.0.1')]
unique_preserved_order = list(dict.fromkeys(spam))
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
crunching ip addresses - by snichols - Nov-09-2020, 03:08 PM
RE: crunching ip addresses - by buran - Nov-10-2020, 08:54 AM
RE: crunching ip addresses - by perfringo - Nov-10-2020, 09:22 AM
RE: crunching ip addresses - by buran - Nov-10-2020, 10:12 AM
RE: crunching ip addresses - by DeaD_EyE - Nov-10-2020, 10:32 AM
RE: crunching ip addresses - by snichols - Nov-10-2020, 05:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  a function to get IP addresses of interfaces Skaperen 2 1,484 May-30-2022, 05:00 PM
Last Post: Skaperen
  Loop through list of ip-addresses [SOLVED] AlphaInc 7 4,207 May-11-2022, 02:23 PM
Last Post: menator01
  instance methods sharing addresses mim 1 2,290 Mar-28-2021, 05:22 AM
Last Post: deanhystad
  Convert email addresses to VCF format jehoshua 2 4,763 Mar-06-2021, 12:50 AM
Last Post: jehoshua
  extract email addresses from gmail vigneshboolog 0 1,827 Feb-11-2020, 09:23 AM
Last Post: vigneshboolog
  Extract email addresses from string and store them in a list oslosurfer 2 2,791 Nov-24-2019, 03:35 PM
Last Post: oslosurfer
  Read list of IP addresses from file and return a network dflick 4 4,997 Oct-27-2018, 09:33 AM
Last Post: buran
  Help required to print MAC addresses anna 50 21,276 Feb-22-2018, 09:53 AM
Last Post: anna
  How do I get coordinates for addresses from the csv list? BigD 6 7,983 Dec-02-2017, 09:38 PM
Last Post: BigD
  How to get data instead of memory addresses KBingo 3 14,422 Jun-12-2017, 12:36 AM
Last Post: KBingo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020