TypeError: 'bool' object is not iterable when finding second-highest number in Python
01:41 24 Aug 2026

I am trying to find the second-highest unique number from a Python list.

My code is:

numbers = [10, 25, 5, 40, 40, 15]

unique_numbers = list(set(numbers))
unique_numbers.sort(reverse=True)

print(unique_numbers[1])

This code gives me the expected output:

25

However, I previously received this error:

TypeError: 'bool' object is not iterable

The code that caused the error was:

result = True

for x in result:
    print(x)

I understand that True is a Boolean value, but I am not sure why Python says it is not iterable.

Could someone explain why this error occurs and how I should identify this type of error in Python?

python-3.x list max min