#Community Practice Problem (dict and tuple)

Q.1 Write a program to get key for given value in dictionary.
Q.2 Write a program to reverse a tuple.

1 Like
def get_key_by_value(dictionary, value):
    for key, val in dictionary.items():
        if val == value:
            return key
    return None

# Testing the function
my_dict = {'a': 1, 'b': 2, 'c': 3}
search_value = 2
result = get_key_by_value(my_dict, search_value)
print(result)  

# Output: 'b'

2.Question

def reverse_tuple(tup):
    reversed_tup = tup[::-1]
    return reversed_tup
my_tuple = (1, 2, 3, 4, 5)
result = reverse_tuple(my_tuple)
print(result) 
3 Likes

Well Done!! Keep Practicing @thejaswini248