Dev Duel

Python Challenges

Sharpen syntax, loops, functions, lists, dictionaries, and more.

Filter challenges

Narrow down by difficulty or category.

Showing 39 of 39 challenges

All challenges

Practice concepts, improve problem-solving, and build confidence.

beginner7 minutes

Count Even Numbers

Count how many even numbers appear in a list.

loopsloopsconditionals
beginner10 minutes

Sum All Odd Numbers in a List

Write a function that calculates the sum of all odd numbers in a given list of integers.

functionsloopsconditional statements
advanced15 minutes

Fix Bug in Complex Recursive Depth-First Search Algorithm for Graph Cycle Detection

Identify and correct the logical errors in a recursive depth-first search (DFS) implementation designed to detect cycles in a directed graph. The provided code attempts to return True if a cycle exists, but it fails in some cases. Your task is to debug and fix the code while preserving its overall structure and efficiency.

debugginggraph theorydepth-first search
advanced10 minutes

Predict the Output of a Recursive Generator with Complex State

Analyze the output of a Python function that uses recursion, generators, and mutable state to yield a sequence of numbers based on intricate control flow.

logicrecursiongenerators
beginner10 minutes

Build a Function to Check Even or Odd Numbers

Create a simple Python function that takes an integer as input and returns whether the number is 'Even' or 'Odd'. This helps beginners practice conditionals and function definitions.

functionsfunctionsconditionals
advanced15 minutes

Fix the Infinite Recursion Bug in a Python Memoization Function

Identify and fix a subtle bug causing infinite recursion in a Python function designed to compute Fibonacci numbers with memoization. The code uses a dictionary cache but incorrectly implements memoization logic, leading to recursion errors. Your task is to debug the function to correctly utilize memoization and efficiently compute Fibonacci values.

debuggingrecursionmemoization
intermediate10 minutes

Refactor and Simplify Nested Loops for Data Aggregation

Improve the structure and readability of a Python function that aggregates sales data from multiple stores and products, while preserving its original behavior.

code-qualityrefactoringnested loops
intermediate10 minutes

Predict the Output of Nested List Comprehensions with Conditional Logic

Analyze nested list comprehensions with conditional statements and predict the final output of the given Python code snippet.

logiclist comprehensionsconditional expressions
advanced15 minutes

Build a Decorator to Cache Function Results with Expiry

Create a Python decorator function that caches the results of an expensive function call, with support for automatic expiration of cached values after a given time-to-live (TTL).

functionsdecoratorscaching
intermediate10 minutes

Predict the Output: List and Dictionary Comprehension Logic

Analyze the given Python code containing nested list and dictionary comprehensions along with conditional logic, and predict the exact output it produces.

logicdictionary comprehensionlist comprehension
advanced10 minutes

Predict the Output of Recursive Memoized Logic on Nested Tuples

Analyze a Python function that performs recursive computations with memoization on a nested tuple input. Predict the final output when the function is called with a complex nested structure.

logicrecursionmemoization
intermediate30 minutes

Build a Movie Recommendation Engine Based on User Ratings

Create a Python mini-project that recommends movies to a user based on their past ratings and similarity to other users' ratings. Implement basic collaborative filtering logic without external libraries.

mini-projectscollaborative filteringmatrix operations
beginner10 minutes

Refactor Messy Code to Improve Readability and Maintainability

You are given a Python function that calculates the sum of even numbers from a list. The current implementation works correctly but is hard to read and maintain. Your task is to refactor the code to make it cleaner and more Pythonic while keeping the behavior the same.

code-qualityfunctionsloops
intermediate10 minutes

Create a Function to Calculate Moving Average of a List

Write a Python function that computes the moving average over a specified window size for a list of numerical values.

functionslist slicingloops
advanced15 minutes

Refactor Legacy Data Processor for Improved Readability and Performance

You are provided with a legacy Python function that processes a list of user records to generate a summary report. Although the function works correctly, it is difficult to read, contains redundant computations, and has inefficient constructs. Your task is to refactor this code to improve readability, maintain the same behavior, and optimize performance while adhering to Python best practices.

code-qualitycode refactoringperformance optimization
intermediate10 minutes

Refactor Nested Loops and Conditionals for Student Grade Processing

Improve the readability and efficiency of a Python function that processes student grades to calculate averages and determine pass/fail status.

code-qualityrefactoringlist comprehensions
beginner10 minutes

Fix the Bug in the Sum of Even Numbers Function

A simple Python function is intended to sum all even numbers from a list, but it contains a bug. Your task is to identify and fix the bug so the function returns the correct sum of even numbers.

debuggingmodulus operatorfor loops
advanced15 minutes

Refactor and Optimize Complex Data Processing Function

Given a large-function script that processes a nested data structure with redundant loops and poor readability, refactor the code to improve maintainability, reduce complexity, and optimize performance without changing its output.

code-qualitycode refactoringperformance optimization
intermediate10 minutes

Build a Expense Tracker with Category Summaries

Create a Python function that manages a list of expenses and produces a summary by category, enabling users to track their spending habits effectively.

mini-projectsdictionarieslist iteration
intermediate10 minutes

Build a Function to Flatten a Nested List of Integers

Create a Python function that takes a nested list of integers and returns a flat list containing all the integers in their original order.

functionsrecursionlist manipulation
intermediate10 minutes

Predict the Output of a Nested List and Dictionary Manipulation

Analyze the given Python code that manipulates nested lists and dictionaries, and predict its exact printed output.

logicmutable objectslist and dictionary references
advanced15 minutes

Build a Function to Serialize and Deserialize Nested Dictionaries with Custom Rules

Create a Python function to serialize a nested dictionary into a custom string format and another function to revert it back, handling complex nesting and type conversions.

functionsrecursionstring parsing
intermediate10 minutes

Refactor and Improve Readability of a Data Filtering Function

Refactor a given Python function that filters and processes a list of dictionaries to improve its code quality, readability, and maintainability without altering its output behavior.

code-qualitycode refactoringlist comprehensions
advanced90 minutes

Advanced Data Pipeline: Build a Custom ETL Framework in Python

Create a scalable, modular Extract-Transform-Load (ETL) mini-project that reads data from multiple formats, applies complex transformations, and loads the result into a target data structure.

mini-projectsETL pipeline designmodular programming
beginner10 minutes

Predict the Output of a Simple Number Check Function

Analyze a Python function that checks if a number is positive, negative, or zero, and predict its output for given inputs.

logicconditionalsfunctions
intermediate10 minutes

Refactor a Function to Cleanly Process and Summarize Sales Data

Improve the clarity, efficiency, and readability of a Python function that processes a list of sales records and returns a summary of total sales by product category.

code-qualitydata aggregationdictionary operations
intermediate15 minutes

Build a Personal Expense Tracker Mini Project

Create a Python program that allows users to add, view, and analyze their personal expenses over time, helping them track spending habits.

mini-projectslists and dictionariesloop and conditionals
beginner10 minutes

Create a Function to Calculate the Square of a Number

Write a Python function that takes a single number as input and returns its square. This is a fundamental exercise to practice defining functions and using arithmetic operators.

functionsfunctionsarithmetic operators
beginner10 minutes

Fix the Bug in Function to Calculate Total Price with Tax

A simple Python function is intended to calculate the total price of an item after adding tax. However, the function contains a bug causing incorrect results. Your task is to find and fix the bug so the function returns the correct total price.

debuggingbasic arithmetic operationsfunction definitions
beginner10 minutes

Create a Simple To-Do List Manager

Build a basic to-do list manager function that allows adding tasks, marking them as complete, and viewing remaining tasks.

mini-projectslistsdictionaries
intermediate10 minutes

Refactor a Function to Compute Unique Elements Frequency

Improve the provided Python function that calculates the frequency of unique elements in a list. Refactor the code for better readability, efficiency, and Pythonic style without changing its behavior.

code-qualitydictionarycollections.Counter
advanced15 minutes

Build a High-Performance Memoized Recursive Function for Multivariate Fibonacci Sequence

Create a Python function that computes terms of a custom multivariate Fibonacci sequence with dynamic step parameters and optimized with memoization for high performance.

functionsrecursionmemoization
intermediate10 minutes

Fix Bug in List Squaring Function with Incorrect Loop

This debugging challenge requires identifying and fixing a bug in a Python function that squares each element of a list but returns incorrect results due to loop errors.

debuggingloopslists
intermediate15 minutes

Build a Task Manager CLI Application in Python

Create a command-line task manager in Python that allows users to add, complete, delete, and list tasks with due dates and priorities.

mini-projectsdatetime handlinglist sorting
intermediate10 minutes

Build a Function to Group and Summarize Sales Data by Category

Create a Python function that takes a list of sales records and returns a summary dictionary grouping total sales by product category.

functionsdictionaryloops
beginner10 minutes

Refactor Messy Code to Calculate the Sum of Even Numbers

Improve the readability and quality of a Python function that calculates the sum of even numbers from a list, while keeping the output correct.

code-qualityloopsconditionals
advanced45 minutes

Build a Concurrent Task Scheduler with Priority Queues

Create a Python mini-project that simulates a concurrent task scheduler managing tasks with different priorities. The scheduler should execute tasks in priority order and support concurrent execution with a fixed number of worker threads.

mini-projectsthreadingpriority queue
intermediate15 minutes

Expense Tracker CLI Application

Build a command-line expense tracker application in Python that allows users to add, view, and categorize their expenses. The program should support adding multiple expenses, filtering expenses by category, and displaying the total amount spent.

mini-projectsfunctionslists
advanced10 minutes

Predict the Output of Nested Generator and Coroutine Logic in Python

Analyze a complex Python function that uses nested generators, coroutines, and yield expressions to predict its output. This challenge tests your understanding of Python's generator mechanics and flow control.

logicgeneratorscoroutines