Delete Prussia from country_capital. Sample output with input: 'Spain:Madrid, Togo:Lome, Prussia:Konigsberg' Prussia deleted? Yes. Spain deleted? No. Togo deleted? No.
Delete Prussia from country_capital. Sample output with input: 'Spain:Madrid, Togo:Lome, Prussia:Konigsberg' Prussia deleted? Yes. Spain deleted? No. Togo deleted? No.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
![## Delete Prussia from `country_capital`
This lesson demonstrates how to delete an entry from a dictionary in Python. The task involves removing the entry for "Prussia" from a `country_capital` dictionary.
### Sample Output
Given the input:
```
'Spain:Madrid,Togo:Lome,Prussia:Konigsberg'
```
The program will output:
```
Prussia deleted? Yes.
Spain deleted? No.
Togo deleted? No.
```
### Code Explanation
```python
1 user_input = input()
2 entries = user_input.split(',')
3 country_capital = {}
4
5 for pair in entries:
6 split_pair = pair.split(':')
7 country_capital[split_pair[0]] = split_pair[1]
8 # country_capital is a dictionary, Ex. {'Germany': 'Berlin', 'France': 'Paris'}
9
10
11 print('Prussia deleted?', end=' ')
12 if 'Prussia' in country_capital:
13 print('No.')
14 else:
15 print('Yes.')
```
#### Code Breakdown
- **Line 1:** Takes user input.
- **Line 2:** Splits the input string into individual country-capital pairs.
- **Line 3:** Initializes an empty dictionary named `country_capital`.
- **Lines 5-7:** Iterates over each pair, splits it by the colon `:`, and adds the country and its capital to the `country_capital` dictionary.
- **Comment on Line 8:** Provides an example of what the `country_capital` dictionary looks like, with countries as keys and capitals as values.
- **Line 11:** Checks if 'Prussia' is in the `country_capital` dictionary.
- **Lines 12-15:** Prints 'No' if Prussia is still present, and 'Yes' if it has been deleted.
### Educational Insight
This exercise helps understand basic dictionary operations in Python, including how to populate a dictionary and check for the existence of a key. Understanding these operations is fundamental for managing data efficiently in Python.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F9978ffa8-8e6a-4550-8363-e044b6a6e895%2F390aa80c-2ade-4a94-af97-5ad8fff0cebe%2Fs2fnl74_processed.png&w=3840&q=75)
Transcribed Image Text:## Delete Prussia from `country_capital`
This lesson demonstrates how to delete an entry from a dictionary in Python. The task involves removing the entry for "Prussia" from a `country_capital` dictionary.
### Sample Output
Given the input:
```
'Spain:Madrid,Togo:Lome,Prussia:Konigsberg'
```
The program will output:
```
Prussia deleted? Yes.
Spain deleted? No.
Togo deleted? No.
```
### Code Explanation
```python
1 user_input = input()
2 entries = user_input.split(',')
3 country_capital = {}
4
5 for pair in entries:
6 split_pair = pair.split(':')
7 country_capital[split_pair[0]] = split_pair[1]
8 # country_capital is a dictionary, Ex. {'Germany': 'Berlin', 'France': 'Paris'}
9
10
11 print('Prussia deleted?', end=' ')
12 if 'Prussia' in country_capital:
13 print('No.')
14 else:
15 print('Yes.')
```
#### Code Breakdown
- **Line 1:** Takes user input.
- **Line 2:** Splits the input string into individual country-capital pairs.
- **Line 3:** Initializes an empty dictionary named `country_capital`.
- **Lines 5-7:** Iterates over each pair, splits it by the colon `:`, and adds the country and its capital to the `country_capital` dictionary.
- **Comment on Line 8:** Provides an example of what the `country_capital` dictionary looks like, with countries as keys and capitals as values.
- **Line 11:** Checks if 'Prussia' is in the `country_capital` dictionary.
- **Lines 12-15:** Prints 'No' if Prussia is still present, and 'Yes' if it has been deleted.
### Educational Insight
This exercise helps understand basic dictionary operations in Python, including how to populate a dictionary and check for the existence of a key. Understanding these operations is fundamental for managing data efficiently in Python.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education