Master Basic List Operations in Python — Without Using Built-in Methods (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] 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

Apr 28, 2025 - 11:16
 0
Master Basic List Operations in Python — Without Using Built-in Methods (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]
  • 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

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
  • 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)

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!"