collection data types processingonce for each unique address assuming that the ip addresses are hashable and are in iterable ipsand that the function we want called for each one is called process_ip(and is already definedthe following code snippets will do what we wantalthough with subtly different behaviorseen set(for ip in ipsif ip not in seenseen add(ipprocess_ip(ipfor ip in set(ips)process_ip(ipfor the left-hand snippetif we haven' processed the ip address beforewe add it to the seen set and process itotherwisewe ignore it for the right-hand snippetwe only ever get each unique ip address to process in the first place the differences between the snippets are first that the left-hand snippet creates the seen set which the right-hand snippet doesn' needand second that the lefthand snippet processes the ip addresses in the order they are encountered in the ips iterable while the right-hand snippet processes them in an arbitrary order the right-hand approach is easier to codebut if the ordering of the ips iterable is important we must either use the left-hand approach or change the right-hand snippet' first line to something like for ip in sorted(set(ips))if this is sufficient to get the required order in theory the right-hand approach might be slower if the number of items in ips is very largesince it creates the set in one go rather than incrementally sets are also used to eliminate unwanted items for exampleif we have list of filenames but don' want any makefiles included (perhaps because they are generated rather than handwritten)we might writefilenames set(filenamesfor makefile in {"makefile""makefile""makefile"}filenames discard(makefilethis code will remove any makefile that is in the list using any of the standard capitalizations it will do nothing if no makefile is in the filenames list the same thing can be achieved in one line using the set difference (-operatorfilenames set(filenames{"makefile""makefile""makefile"we can also use set remove(to remove itemsalthough this method raises keyerror exception if the item it is asked to remove is not in the set