🚀 Day 2: Coding Problems on Lists, Tuples, Sets & Dictionaries

Problem 1: Reverse a List

Write a Python program to reverse a given list without using the built-in reverse() method.

Input: [1, 2, 3, 4]
Output: [4, 3, 2, 1]

Problem 2: Sum of Tuple Elements

Given a tuple of numbers, return the sum of all elements.

Input: (1, 2, 3, 4)
Output: 10

Problem 3: Remove Duplicates from List

Write a function to remove all duplicate items from a list using a set.

Input: [1, 2, 2, 3, 4, 4, 5]
Output: [1, 2, 3, 4, 5]

Problem 4: Frequency of Elements

Given a list of elements, return a dictionary with the frequency of each element.

Input: ['a', 'b', 'a', 'c', 'b', 'a']
Output: {'a': 3, 'b': 2, 'c': 1}

Problem 5: Access Nested Dictionary

Given a nested dictionary, access the inner value safely.

Input:
data = {
  "student": {
    "name": "Alice",
    "marks": {
      "math": 95
    }
  }
}
Output: 95

Problem 6: Intersection of Two Sets

Write a Python function that returns the common elements from two sets.

Input: set1 = {1, 2, 3}, set2 = {2, 3, 4}
Output: {2, 3}