cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How can I remove a key from a Python dictionary?

Kaniz
Community Manager
Community Manager
 
3 REPLIES 3

spark-user
Contributor

Hi Kaniz,

You can remove it by using the pop method

dict.pop('key', None)

It is a safe way to delete a key even if you are not sure it exists. The second parameter is optional also.

You can read more about the method here.

 Thank you

Kaniz
Community Manager
Community Manager

Thank you @spark-user.

No problem!