Featured Post

14 Top Data Pipeline Key Terms Explained

Image
 Here are some key terms commonly used in data pipelines 1. Data Sources Definition: Points where data originates (e.g., databases, APIs, files, IoT devices). Examples: Relational databases (PostgreSQL, MySQL), APIs, cloud storage (S3), streaming data (Kafka), and on-premise systems. 2. Data Ingestion Definition: The process of importing or collecting raw data from various sources into a system for processing or storage. Methods: Batch ingestion, real-time/streaming ingestion. 3. Data Transformation Definition: Modifying, cleaning, or enriching data to make it usable for analysis or storage. Examples: Data cleaning (removing duplicates, fixing missing values). Data enrichment (joining with other data sources). ETL (Extract, Transform, Load). ELT (Extract, Load, Transform). 4. Data Storage Definition: Locations where data is stored after ingestion and transformation. Types: Data Lakes: Store raw, unstructured, or semi-structured data (e.g., S3, Azure Data Lake). Data Warehous...

How to Delete an Item from a Set in Python: Best Example

Set is a built-in data type in Python. Furthermore, it is an unordered collection without duplicate items. Here are the two methods that explain to delete an item from a Set.

Methods to delete an item from a Set

  • discard
  • remove



Discrd Vs. Remove


  • discard() will not raise an error if the item to remove does not exist.
  • The remove() will raise an error if the item does not exist.


Remove items from Set


Explanation to discard and remove methods


Python program:

#Prints all the Set items

food = {"pasta", "burger", "hot dog", "pizza"}

print(food)


# Prints the Set items without pasta

food.discard("pasta")

print(food)


# Prints the Set items without burger and pasta

food.remove("burger")

print(food)


# The next two lines try to remove an item that isn't in the set!

food.discard("pasta")  # this will not report an error

food.remove("pasta")   # this will report an error


The output:

{'pasta', 'burger', 'pizza', 'hot dog'}

{'burger', 'pizza', 'hot dog'}

{'pizza', 'hot dog'}

Traceback (most recent call last):

  File "main.py", line 12, in <module>

    food.remove("pasta")   # this will report an error

KeyError: 'pasta'


** Process exited - Return Code: 1 **

Press Enter to exit terminal


Related

Comments

Popular posts from this blog

How to Fix datetime Import Error in Python Quickly

SQL Query: 3 Methods for Calculating Cumulative SUM

Big Data: Top Cloud Computing Interview Questions (1 of 4)