29-sept Data Structurer

 29-sept Data Structurer



LAB1: Write a Python function create_data structures) that performs the following tasks: 

 1. Create a list called my_list containing the numbers [1, 2, 3]. 

 2. Create a tuple called my tuple containing the strings (“apple”, “banana, “cherry").

 3. Create a dictionary called my_dict with keys as {"name": "Alice", "age": 25).

 4. Create a set called my_set with values {1, 2, 3). Your function should return all four data structures as a tuple in the order: (list, tuple, dictionary, set).

def create_data_structures():
    my_list = [1, 2, 3]
    my_tuple = ("apple", "banana", "cherry")
    my_dict = {"name": "Alice", "age": 25}
    my_set = {1, 2, 3}
    
    return (my_list, my_tuple, my_dict, my_set)
LAB2: Write a Python function get second color(colors) that takes a tuple of colors as input and returns the second color in the tuple.
def get_second_color(colors):
    return colors[1]

# Example usage:
colors = ("red", "blue", "green")
print(get_second_color(colors)) 

LAB 3: Write a Python function get_capital(capitals, country) that takes a dictionary capitals and a string country, and returns the capital of that country.

def get_capital(capitals, country):
    return capitals.get(country, "Country not found")
capitals = {
    "France": "Paris",
    "Germany": "Berlin",
    "Italy": "Rome",
    "Spain": "Madrid"
}

print(get_capital(capitals, "France"))  # Output: Paris
print(get_capital(capitals, "Canada"))  

LAB 4: Write a Python function update_sports(sports) that takes a set of ports, adds "cricket" to it, removes "tennis", and returns the updated set.

def update_sports(sports):
    sports.add("cricket")   
    sports.discard("tennis")  
    return sports
current_sports = {"soccer", "basketball", "tennis"}
updated_sports = update_sports(current_sports)

print(updated_sports)