TypeError: 'bool' object is not iterable when finding second-highest number in Python
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?