How to Divide Each Element in a List by a Number in Python

To divide each element in a list by a number in Python, use a list comprehension: [x / n for x in values]. It builds a new list, and the original isn’t changed:

values = [10, 25, 40]
halves = [x / 2 for x in values]   # [5.0, 12.5, 20.0]

Every output on this page comes straight from my own machine, running Python 3.12.5 and NumPy 2.5.3 in Command Prompt.

You’ll also see map(), floor division, NumPy, zero values and percentages.

Divide each list element with a list comprehension

Here I split yearly bills into monthly amounts. / returns floats, so I round dollars to 2 places:

annual_costs = [1200.00, 2450.50, 980.00, 3600.00]   # yearly bills in USD

monthly = [cost / 12 for cost in annual_costs]
print(monthly)

monthly_usd = [round(cost / 12, 2) for cost in annual_costs]
print(monthly_usd)
print(annual_costs)   # the original list is unchanged

Output:

[100.0, 204.20833333333334, 81.66666666666667, 300.0]
[100.0, 204.21, 81.67, 300.0]
[1200.0, 2450.5, 980.0, 3600.0]
Command Prompt output of a Python list comprehension dividing each yearly cost in a list by 12
Each yearly cost is divided by 12; round() trims each result to at most 2 decimals, and the original list is untouched.

If you want to skip or change some items while dividing, add a condition, as shown in my guide to list comprehension with if-else in Python.

Divide list elements with a for loop or map()

A loop reads better when each step needs more logic; map() does the same job in one line:

race_km = [42.195, 21.0975, 10.0, 5.0]
KM_PER_MILE = 1.609344

miles = []
for km in race_km:
    miles.append(round(km / KM_PER_MILE, 2))
print("for loop:", miles)

print("map():   ", list(map(lambda km: round(km / KM_PER_MILE, 2), race_km)))

Output:

for loop: [26.22, 13.11, 6.21, 3.11]
map():    [26.22, 13.11, 6.21, 3.11]

Both give the same miles. For more on the function itself, see the map() function in Python.

Should you use / or // to divide a list?

/ keeps the fraction. // is floor division: it rounds down, which surprises people with negative numbers:

values = [99, -99, 50, 7]

print("/     ", [x / 7 for x in values])
print("//    ", [x // 7 for x in values])        # rounds down, even for negatives
print("int() ", [int(x / 7) for x in values])    # cuts toward zero instead

Output:

/      [14.142857142857142, -14.142857142857142, 7.142857142857143, 1.0]
//     [14, -15, 7, 1]
int()  [14, -14, 7, 1]
Command Prompt output comparing Python true division, floor division and int() on each element of a list
Floor division turns -99 / 7 into -15, while int() cuts the same value to -14.

Use // only when rounding down is what you mean. The details are in normal division vs floor division in Python.

Divide a list by a number with NumPy

A plain list can’t be divided directly, but a NumPy array can, in one fast step:

import numpy as np

prices = [19.99, 249.00, 5.49, 1299.00]   # USD, split into 4 payments

try:
    prices / 4
except TypeError as err:
    print("plain list:", err)

arr = np.array(prices)
print("array:     ", arr / 4)
print("as list:   ", np.round(arr / 4, 2).tolist())

Output:

plain list: unsupported operand type(s) for /: 'list' and 'int'
array:      [  4.9975  62.25     1.3725 324.75  ]
as list:    [5.0, 62.25, 1.37, 324.75]
Command Prompt output showing a TypeError when dividing a Python list by 4, then a NumPy array divided by 4
The list raises a TypeError; the NumPy array divides all four prices at once.

.tolist() gives you a regular list back, which is covered in converting a NumPy array to a list. For np.divide() and dividing two arrays, read NumPy divide in Python.

How do you handle zero or text values when dividing a list?

Dividing by zero raises ZeroDivisionError, and a string in the list raises TypeError. This helper checks the divisor, converts numeric strings and skips None:

def divide_all(values, divisor):
    if divisor == 0:
        raise ValueError("divisor can't be zero")
    return [float(v) / divisor for v in values if v is not None]

print(divide_all(["120.50", 80, None, "45"], 5))

try:
    print([v / 0 for v in [10, 20]])
except ZeroDivisionError as err:
    print("ZeroDivisionError:", err)

Output:

[24.1, 16.0, 9.0]
ZeroDivisionError: division by zero

float() still fails on text like "N/A", so clean those first. My guide on converting a string to a float in Python shows how.

Divide a list by its sum to get percentages

Dividing every value by the list’s own total turns sales by state into shares:

sales = {"California": 48250.00, "Texas": 31900.00,
         "New York": 27350.00, "Florida": 18500.00}

total = sum(sales.values())
shares = [amount / total for amount in sales.values()]

print(f"Total sales: ${total:,.2f}")
for state, share in zip(sales, shares):
    print(f"{state:<11} {share:7.2%}")

Output:

Total sales: $126,000.00
California   38.29%
Texas        25.32%
New York     21.71%
Florida      14.68%
Command Prompt output of Python dividing each state's sales in a list by the total to show percentage shares
Each state’s sales are divided by the total and printed as a percentage.

The :.2% format multiplies by 100. For the average instead, see finding the average of a list in Python.

If you’re working through list math, these pages pick up from here:

Frequently asked questions

How do I divide every element in a list by a number in Python?

Use a list comprehension such as [x / n for x in values]. It returns a new list of floats.

Why can’t I write my_list / 2 in Python?

Lists don’t support /, so Python raises a TypeError. Use a comprehension or a NumPy array.

How do I divide a list and keep whole numbers?

Use // to round down or int(x / n) to cut toward zero. They differ for negative numbers.

How do I round the results to 2 decimal places?

Wrap the division in round(), for example [round(x / 12, 2) for x in costs].

Can I change the original list instead of making a new one?

Yes. Loop with enumerate() and assign values[i] = values[i] / n, or use slice assignment: values[:] = [x / n for x in values].

Where are Python’s division operators documented?

See binary arithmetic operations in the Python language reference.