Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Del Keyword | Dictionary
Python Data Structures
course content

Course Content

Python Data Structures

Python Data Structures

1. List
2. Dictionary
3. Tuple
4. Set

bookDel Keyword

In a dictionary, you can remove keys using the del keyword. With it, you can delete specific entries or even the entire dictionary. Here's how you can do it:

123456
# Creating a dictionary dict_1 = {10: 'apple', 20: 'banana', 15: 'cherry', 30: 'apricot', 27: 'grape'} # Deleting a key value del dict_1[30] print(dict_1)
copy

Task

Consider this dictionary:

{'country_1': 'India', 'country_2': 'Latvia', 'country_3': 'Panama', 'country_4': 'Serbia'}

Your goal is to modify it to look like this:

{'country_2': 'Latvia', 'country_3': 'Panama'}

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 5
toggle bottom row

bookDel Keyword

In a dictionary, you can remove keys using the del keyword. With it, you can delete specific entries or even the entire dictionary. Here's how you can do it:

123456
# Creating a dictionary dict_1 = {10: 'apple', 20: 'banana', 15: 'cherry', 30: 'apricot', 27: 'grape'} # Deleting a key value del dict_1[30] print(dict_1)
copy

Task

Consider this dictionary:

{'country_1': 'India', 'country_2': 'Latvia', 'country_3': 'Panama', 'country_4': 'Serbia'}

Your goal is to modify it to look like this:

{'country_2': 'Latvia', 'country_3': 'Panama'}

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 5
toggle bottom row

bookDel Keyword

In a dictionary, you can remove keys using the del keyword. With it, you can delete specific entries or even the entire dictionary. Here's how you can do it:

123456
# Creating a dictionary dict_1 = {10: 'apple', 20: 'banana', 15: 'cherry', 30: 'apricot', 27: 'grape'} # Deleting a key value del dict_1[30] print(dict_1)
copy

Task

Consider this dictionary:

{'country_1': 'India', 'country_2': 'Latvia', 'country_3': 'Panama', 'country_4': 'Serbia'}

Your goal is to modify it to look like this:

{'country_2': 'Latvia', 'country_3': 'Panama'}

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

In a dictionary, you can remove keys using the del keyword. With it, you can delete specific entries or even the entire dictionary. Here's how you can do it:

123456
# Creating a dictionary dict_1 = {10: 'apple', 20: 'banana', 15: 'cherry', 30: 'apricot', 27: 'grape'} # Deleting a key value del dict_1[30] print(dict_1)
copy

Task

Consider this dictionary:

{'country_1': 'India', 'country_2': 'Latvia', 'country_3': 'Panama', 'country_4': 'Serbia'}

Your goal is to modify it to look like this:

{'country_2': 'Latvia', 'country_3': 'Panama'}

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 2. Chapter 5
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt