Chapter 8 Assignments: Core Data Structures

Basic Questions

  1. Write a program to create a list of numbers from 1 to 10 using the range() function.
  2. Create a tuple with the names of five fruits and print the third fruit.
  3. Write a function that takes two numbers and returns their sum.
  4. Create a set with five unique integers and print its length.
  5. Write a dictionary to store three student names as keys and their scores as values.
  6. Convert a list of numbers to a tuple and print the tuple.
  7. Use a for loop to iterate over a list of strings and print each string.
  8. Create an OrderedDict with three key-value pairs and print its keys in insertion order.
  9. Write a function that returns the maximum of three numbers.
  10. Create a set, add two elements to it, and check if a specific element exists in the set.

Intermediate Questions

  1. Write a function that returns a list of even numbers from 1 to 50 using range() and list comprehension.
  2. Create a dictionary where keys are numbers from 1 to 5 and values are their squares.
  3. Given a tuple of integers, write code to find the sum of all elements.
  4. Write a function to merge two sets and return the resulting set without duplicates.
  5. Use an OrderedDict to maintain and print the order of insertion of items added dynamically in a loop.
  6. Create a function that accepts a dictionary and returns a list of keys sorted alphabetically.
  7. Write code to convert a string to a list of characters and then to a set to remove duplicates.
  8. Define a function that returns the first n Fibonacci numbers as a list using tuples.
  9. Use a list and dictionary to count the frequency of each character in a given string.
  10. Write a function to clear all items from a set and verify it is empty.

Advanced Questions

  1. Implement a function to reverse the keys and values of a dictionary and return a new dictionary.
  2. Write code to sort a list of tuples by the second element using sorted() and lambda functions.
  3. Create a nested dictionary representing a student's details (name, subjects, and scores) and print the average score.
  4. Write a function that finds common elements in two lists using set operations and returns them sorted.
  5. Use OrderedDict to implement a simple Least Recently Used (LRU) cache with capacity 3 for integer keys.
  6. Implement a function to flatten a nested list into a single list using recursion.
  7. Write code to count the frequency of words in a large text using a dictionary and then print the top 5 most common words.
  8. Create a function to perform deep copy of a dictionary containing nested dictionaries without using copy.deepcopy().
  9. Write a function that accepts any number of lists and returns a merged set of unique elements.
  10. Implement a generator function that yields tuples of (index, value) for a list, mimicking enumerate().