Featured Post

8 Ways to Optimize AWS Glue Jobs in a Nutshell

  Improving the performance of AWS Glue jobs involves several strategies that target different aspects of the ETL (Extract, Transform, Load) process. Here are some key practices. 1. Optimize Job Scripts Partitioning : Ensure your data is properly partitioned. Partitioning divides your data into manageable chunks, allowing parallel processing and reducing the amount of data scanned. Filtering : Apply pushdown predicates to filter data early in the ETL process, reducing the amount of data processed downstream. Compression : Use compressed file formats (e.g., Parquet, ORC) for your data sources and sinks. These formats not only reduce storage costs but also improve I/O performance. Optimize Transformations : Minimize the number of transformations and actions in your script. Combine transformations where possible and use DataFrame APIs which are optimized for performance. 2. Use Appropriate Data Formats Parquet and ORC : These columnar formats are efficient for storage and querying, signif

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"}


# Prints the Set items without pasta



# Prints the Set items without burger and pasta



# 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



Popular posts from this blog

How to Fix datetime Import Error in Python Quickly

How to Check Kafka Available Brokers

SQL Query: 3 Methods for Calculating Cumulative SUM