Sets in Python

A set is an unordered collection of elements without any duplicates.

Sets are especially useful for performing logical operations like finding the union, intersection, or difference between collections of elements. For example, sets could be used to determine mutual friends on a social networking site.

Syntax :

x = set(iterables)

or

x = {value1,value2,value3......valuen}

There are several ways to create a set, which include:

Using the built-in set() function and passing in an optional iterable parameter.

Hard-coding a set with dictionary-like syntax ({}) where each element is unique.

 


Here, it is not printed the GCP name twice, It is a duplicate record & it will only display the Unique records.

The other methods in the sets defined below

.difference():

Returns a new set of objects unique to a given set when compared to others.

.intersection():

Returns a new set with objects that exist inside two or more sets

.union():

Returns a new set that combines objects from all sets involved, removing any duplicates.

Comments

Popular posts from this blog

Db2 export command example using file format (del , ixf)

How to fix DB2 Tablespace OFFLINE state issue?

Phases of a load operation