DEV Community

Cover image for Master Basic List Operations in Python — Without Using Built-in Methods in Python (Part 1)
Peter Muthama
Peter Muthama

Posted on

1

Master Basic List Operations in Python — Without Using Built-in Methods in Python (Part 1)

In today’s post, we dive into performing basic list operations without using built-in Python methods.

Exercises like these help build strong problem-solving skills and deepen your understanding of Data Structures and Algorithms (DSA).


Problem 1: Find the Minimum Value in a List

Problem

You are given a list of integers. Write a function find_min(nums) that returns the minimum number from the list without using Python’s built-in min() function.

If the list is empty, return None.


Breakdown:

  • First, we need a way to keep track of the minimum value. We initialize a variable to the first element:
  min_value = nums[0]
Enter fullscreen mode Exit fullscreen mode
  • Then, loop through the list. For each number, if it is smaller than our current min_value, we update min_value.
  • If the list is empty, return None immediately.

Full Solution:

def find_min(nums):
    if not nums:
        return None

    min_value = nums[0]

    for num in nums:
        if num < min_value:
            min_value = num
    return min_value
Enter fullscreen mode Exit fullscreen mode

Problem 2: Count Even and Odd Numbers

Problem

You are given a list of integers. Return a tuple (even_count, odd_count)

where even_count is the number of even integers, and odd_count is the number of odd integers.

Do not use any built-in Python methods like filter(), count(), etc.


Breakdown:

  • Initialize two counters:
  even_count = 0
  odd_count = 0
Enter fullscreen mode Exit fullscreen mode
  • Loop through each number:
    • If num % 2 == 0, it’s even → increment even_count.
    • Otherwise, it’s odd → increment odd_count.
  • Finally, return a tuple (even_count, odd_count).

Full Solution:

def count_even_odd(nums):
    even_count = 0
    odd_count = 0

    for num in nums:
        if num % 2 == 0:
            even_count += 1
        else:
            odd_count += 1

    return (even_count, odd_count)
Enter fullscreen mode Exit fullscreen mode

Final Thoughts

This marks the first part of practicing basic list operations without built-in functions.

Stay tuned and keep practicing — mastering these basics will give you a huge advantage in both coding interviews and real-world problem solving!


"If you enjoyed this, follow me for more posts on Python, DSA, and practical coding exercises!"

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

Image of PulumiUP 2025

Transform Your Cloud Infrastructure

Join PulumiUP 2025 on May 6 for Expert Insights & Demos.

Register Now

👋 Kindness is contagious

Value this insightful article and join the thriving DEV Community. Developers of every skill level are encouraged to contribute and expand our collective knowledge.

A simple “thank you” can uplift someone’s spirits. Leave your appreciation in the comments!

On DEV, exchanging expertise lightens our path and reinforces our bonds. Enjoyed the read? A quick note of thanks to the author means a lot.

Okay