Bigdata – Knowledge Base

Practice Problem – List, Set, Dictionary, Tuple

Table Of Contents

List #

  1. Sorting and Searching
    • Write a function that sorts a list of strings based on their lengths in descending order.
    • Implement a binary search function that finds the position of a target value within a sorted list.
  2. List Comprehensions with Conditions
    • Use a list comprehension to generate a list of all prime numbers between 1 and 100.
  3. Manipulating Large Lists
    • Given a large list of integers, write a function to find the top 5 largest numbers in the list without sorting the entire list.
  4. Flattening Nested Lists
    • Write a function to flatten a nested list of arbitrary depth (e.g., [[1, [2, 3]], [4, [5, [6, 7]]]] should become [1, 2, 3, 4, 5, 6, 7]).
  5. Finding Common Elements
    • Write a function that takes two lists and returns a list of elements that are present in both lists, without using sets.

Set #

  1. Advanced Set Operations
    • Given two sets, write a function to find the Cartesian product of the sets.
  2. Handling Large Datasets
    • Given a large dataset of integers with potential duplicates, write a function to find all unique elements and their frequencies.
  3. Set Comprehensions
    • Use a set comprehension to create a set of all unique characters in a given string, ignoring case.
  4. Set Operations on Multiple Sets
    • Write a function that takes a list of sets and returns a set that is the union of all the sets.
  5. Performance Comparison
    • Compare the performance of finding the intersection of two large lists using set operations versus list comprehensions.

Dictionary #

  1. Complex Key-Value Pair Manipulation
    • Given a dictionary where keys are strings and values are lists of integers, write a function to find the key with the highest sum of its values.
  2. Merging Dictionaries
    • Write a function to merge two dictionaries. If a key exists in both dictionaries, the value should be a list containing both values.
  3. Dictionary Comprehensions with Conditions
    • Use a dictionary comprehension to create a dictionary from a list of strings, where the keys are the strings and the values are the lengths of the strings, but only include strings longer than 3 characters.
  4. Nested Dictionary Manipulation
    • Given a nested dictionary representing a company structure (e.g., {'CEO': {'VP1': {'Manager1': {}, 'Manager2': {}}, 'VP2': {'Manager3': {}}}}), write a function to add a new employee under a specific manager.
  5. Complex Data Aggregation
    • Write a function that takes a list of dictionaries representing sales data (e.g., {'product': 'A', 'quantity': 10, 'price': 5}) and returns a dictionary with total sales for each product.

Tuple #

  1. Tuple Operations
    • Write a function that takes a list of tuples (representing coordinates) and returns the tuple with the maximum Euclidean distance from the origin.
  2. Unpacking with Patterns
    • Given a list of tuples representing student records (e.g., [(name, age, grade)]), write a function to unpack and process the data to calculate the average grade.
  3. Using Tuples in Data Structures
    • Create a function that takes a list of tuples representing edges in a graph (e.g., [(node1, node2)]) and returns an adjacency list representation of the graph using dictionaries.
  4. Tuple as Dictionary Keys
    • Write a function that counts the frequency of each unique tuple in a list of tuples and stores the result in a dictionary.
  5. Advanced Unpacking Techniques
    • Given a tuple of nested tuples (e.g., ((1, 2), (3, (4, 5)), 6)), write a recursive function to flatten the tuple into a list.
What are your feelings
Updated on July 18, 2024