In this chapter, we'll explore the story of Sodom and Gomorrah and learn about dictionaries in Python programming. The story of Sodom and Gomorrah shows us the consequences of immorality and the importance of making good choices. We will use dictionaries in Python to store and manage information about the cities mentioned in the story, helping us understand the relationships between the cities and their outcomes. This will demonstrate the usefulness of dictionaries in organizing and accessing data efficiently in our programs.

Read the Bible

Genesis 19:1-29

Reflection

  1. In the story of Sodom and Gomorrah, God decided to destroy these cities due to their wickedness. How does this story demonstrate the importance of making moral choices and living in accordance with God's will?
  2. This story involves several cities and their outcomes: Sodom and Gomorrah were destroyed, while Zoar was spared. Each city had a different fate and role in the story. Can you think of a way to keep track of this information in a structured and organized manner?

Learn about programming

Dictionaries

In the story of Sodom and Gomorrah, we heard about different cities and their relationships to Lot and his family. In programming, we can use a data structure called dictionaries to store and manage this kind of information. Dictionaries are like lists, but instead of using indices to access items, we use keys. Each key in a dictionary is unique and maps to a value.

Let's first create a simple dictionary to store information about the cities mentioned in the story:

city_info = {
    'Sodom': 'Destroyed by God',
    'Gomorrah': 'Destroyed by God',
    'Zoar': 'Spared by God'
}

Now, we have a dictionary called city_info ****that holds three different cities and their outcomes. If we want to access the outcome of a specific city, we can use its key:

sodom_outcome = city_info['Sodom']
print(sodom_outcome) # Output: 'Destroyed by God'

Now that we know how to create a simple dictionary, let's build upon that by introducing nested dictionaries. Nested dictionaries are dictionaries inside dictionaries. We can use nested dictionaries to store more detailed information about each city, like their relationship to Lot and his family, and their outcome:

city_info = {
    'Sodom': {
        'relation': 'Lot lived here',
        'outcome': 'Destroyed by God'
    },
    'Gomorrah': {
        'relation': 'Nearby city',
        'outcome': 'Destroyed by God'
    },
    'Zoar': {
        'relation': 'Lot and his family fled here',
        'outcome': 'Spared by God'
    }
}

To access information about a specific city, we can use its key, just like before:

sodom_info = city_info['Sodom']
print(sodom_info) # Output: {'relation': 'Lot lived here', 'outcome': 'Destroyed by God'}

To access more specific information about a city, like its relationship to Lot and his family, we can use a combination of keys:

sodom_relation = city_info['Sodom']['relation']
print(sodom_relation) # Output: 'Lot lived here'

By using dictionaries and nested dictionaries, we can organize and manage complex information efficiently and effectively.