How to Sum a List in Python Without Using sum() (5 Ways)

Say you’re totaling one week of sales for a small coffee shop in Denver: seven daily figures, from $875.50 on a slow Tuesday to $2,105.75 on Friday.

To sum a list in Python without using sum(), start a variable at 0 and add each item to it in a for loop. On that week, the loop lands on $9,621.99, the same as sum().

In this tutorial, I’ll show you how to sum a list in Python without using sum five ways, from the plain loop to reduce(), recursion and accumulate(). You’ll also see the float, empty-list and speed traps. I ran everything on Python 3.12.5.

The weekly sales list we’ll sum in Python

Every example imports the same list from sales.py:

# Daily sales for one week, Mon Oct 19 - Sun Oct 25, 2026 (USD)
daily_sales = [1249.99, 875.50, 1430.25, 962.10, 2105.75, 1688.40, 1310.00]

It’s seven floats in US dollars, which matters later for rounding. New to lists? Start with creating a list in Python.

Method 1: Sum a list with a for loop (Recommended)

This is the version I’d write in an interview or homework answer. It’s short and anyone can read it. Same seven days of sales:

from sales import daily_sales

total = 0
for amount in daily_sales:
    total += amount

print("Days:", len(daily_sales))
print("Week total:", total)
print(f"Week total: ${total:,.2f}")
print("Matches sum():", total == sum(daily_sales))

Output:

Days: 7
Week total: 9621.99
Week total: $9,621.99
Matches sum(): True

The loop lands on $9,621.99, and the last line confirms it matches the built-in.

Command Prompt output of a Python for loop summing a list of seven daily sales without using sum()
The for loop adds all seven days and its total matches what sum() returns.

How does this code work?

total = 0 is the accumulator. Each pass, total += amount adds one day: 1249.99 after Monday, 2125.49 after Tuesday, and so on.

The :,.2f format only changes how the number prints; the stored total isn’t rounded.

When the built-in is allowed, it’s still the better choice. I compare both in summing elements in a Python list.

Method 2: Sum a list with a while loop and an index

A while loop works too, but you manage the index yourself. Same sales list:

from sales import daily_sales

total = 0
i = 0
while i < len(daily_sales):
    total += daily_sales[i]
    i += 1

print(f"While loop total: ${total:,.2f} after {i} days")

Output:

While loop total: $9,621.99 after 7 days

It prints $9,621.99 after 7 days, so it agrees with Method 1.

Important: forget i += 1 and the loop never ends. That’s why I prefer the for loop.

There’s a fuller side-by-side in for loop vs while loop in Python.

Method 3: Sum a list with functools.reduce()

functools.reduce() folds a list into one value with a two-argument function. With operator.add, that fold is a sum:

from sales import daily_sales

from functools import reduce
import operator

print("operator.add:", round(reduce(operator.add, daily_sales), 2))
print("lambda:      ", round(reduce(lambda a, b: a + b, daily_sales), 2))

print("empty + 0:   ", reduce(operator.add, [], 0))
try:
    reduce(operator.add, [])
except TypeError as err:
    print("TypeError:", err)

Output:

operator.add: 9621.99
lambda:       9621.99
empty + 0:    0
TypeError: reduce() of empty iterable with no initial value

Both versions return 9621.99. The empty list gives 0 only when you pass a starting value; without it, Python raises a TypeError.

Command Prompt output of Python functools.reduce summing a list with operator.add and a lambda, plus the empty-list TypeError
reduce() with operator.add or a lambda gives the same total, and an empty list needs the initial 0.

How does this code work?

reduce() adds Monday and Tuesday, then adds Wednesday to that result, and keeps going. The third argument, 0, is the starting value.

operator.add and lambda a, b: a + b do the same job. If lambdas feel odd, read how lambda functions work in Python.

Method 4: Sum a list with recursion

Recursion says the total is the first item plus the total of the rest. Here’s the honest version, limits included:

from sales import daily_sales

import sys

def sum_list(values):
    if not values:              # base case: an empty list adds 0
        return 0
    return values[0] + sum_list(values[1:])

print("Recursive total:", round(sum_list(daily_sales), 2))
print("Recursion limit:", sys.getrecursionlimit())

try:
    sum_list(list(range(1500)))
except RecursionError as err:
    print("RecursionError:", err)

Output:

Recursive total: 9621.99
Recursion limit: 1000
RecursionError: maximum recursion depth exceeded

The recursive total is 9621.99, but a list of 1,500 numbers crashes with a RecursionError.

Command Prompt output of a recursive Python function summing a list, then a RecursionError on 1,500 items
Recursion works on the seven-day list and fails past the default recursion limit of 1000.

How does this code work?

The base case, if not values: return 0, stops the chain. Each call keeps a frame open, and Python’s default limit is 1000.

values[1:] also copies the list on every call. Fine for learning, bad for real data; more in recursion in Python.

Method 5: Sum a list with itertools.accumulate()

accumulate() returns running totals, and the last one is the sum:

from sales import daily_sales

from itertools import accumulate

running = [round(x, 2) for x in accumulate(daily_sales)]
print("Running totals:", running)
print("Week total:", running[-1])

Output:

Running totals: [1249.99, 2125.49, 3555.74, 4517.84, 6623.59, 8311.99, 9621.99]
Week total: 9621.99

By Friday the shop had made $6,623.59, and the final running total is 9621.99.

Pro Tip: use this when a report needs cumulative sales. For the total alone, the loop is simpler.

How do you sum a list of floats without rounding errors?

Here’s where your own loop can quietly disagree with sum(). Ten 10-cent tips should make exactly $1.00:

from decimal import Decimal

tips = [0.10] * 10              # ten 10-cent tips

loop_total = 0
for t in tips:
    loop_total += t

print("for loop:", loop_total)
print("sum():   ", sum(tips))
print("round(): ", round(loop_total, 2))

exact = Decimal("0")
for t in ["0.10"] * 10:
    exact += Decimal(t)
print("Decimal: ", exact)

Output:

for loop: 0.9999999999999999
sum():    1.0
round():  1.0
Decimal:  1.00

The loop prints 0.9999999999999999, while sum() prints 1.0. Rounding and Decimal both give a clean dollar.

Command Prompt output showing a Python for loop summing ten 0.10 floats to 0.9999999999999999 while sum() returns 1.0
The plain loop drifts below 1.0, while sum(), rounding and Decimal give a clean dollar.

How does this code work?

0.10 isn’t stored exactly in binary, so each += adds a tiny error. Since Python 3.12, sum() uses a more accurate float algorithm; see the Python sum() function guide.

For money, I add whole cents or use Decimal. For display only, rounding numbers to 2 decimal places is enough.

Handle empty lists, strings and None in a Python sum loop

Your real data will be messier. This order export has a text price and a missing value:

def total(values):
    running = 0
    for v in values:
        running += v
    return running

print("Empty list:", total([]))

orders = [19.99, "4.50", None, 12.25]
try:
    total(orders)
except TypeError as err:
    print("TypeError:", err)

clean = 0
for v in orders:
    if v is None:
        continue
    clean += float(v)
print("Cleaned total:", round(clean, 2))

weeks = [[1249.99, 875.50], [1430.25], [962.10, 2105.75]]
grand = 0
for week in weeks:
    for day in week:
        grand += day
print("Nested total:", round(grand, 2))

Output:

Empty list: 0
TypeError: unsupported operand type(s) for +=: 'float' and 'str'
Cleaned total: 36.74
Nested total: 6623.59

An empty list returns 0, the raw orders raise a TypeError, the cleaned total is 36.74, and the nested weeks add up to 6623.59.

Skip None and convert text with float() string conversion. For nested data, loop twice or flatten a list of lists first.

Which is fastest: a for loop, reduce() or NumPy?

I timed each approach on one million integers with timeit. Your numbers will differ, but the order tells the story:

import timeit
from functools import reduce
import numpy as np

nums = list(range(1_000_000))
arr = np.array(nums)

def for_loop():
    t = 0
    for x in nums:
        t += x
    return t

tests = {
    "built-in sum()": lambda: sum(nums),
    "for loop": for_loop,
    "reduce(lambda)": lambda: reduce(lambda a, b: a + b, nums),
    "np.add.reduce(list)": lambda: np.add.reduce(nums),
    "np.add.reduce(array)": lambda: np.add.reduce(arr),
}
for name, fn in tests.items():
    ms = min(timeit.repeat(fn, number=5, repeat=3)) / 5 * 1000
    print(f"{name:<22}{ms:8.1f} ms")

Output:

built-in sum()             3.6 ms
for loop                  21.9 ms
reduce(lambda)            44.2 ms
np.add.reduce(list)       29.3 ms
np.add.reduce(array)       0.3 ms

The built-in sum() beat every hand-written option, and the plain loop beat reduce() with a lambda, which pays for a call per item.

NumPy is only fast once the data is already an array; on a plain list, the conversion eats the gain. See NumPy sum in Python.

Which method should you use to sum a list without sum()?

MethodUse it whenWatch out for
for loopAlmost always: interviews, homework, real codeFloat drift on money values
while loopThe task asks for an index or counterForgetting i += 1
reduce()You like a functional one-linerEmpty list needs an initial 0
RecursionLearning or a recursion exerciseRecursionError past ~1000 items
accumulate()You also want running totalsBuilds a full list in memory