[Tutor] Occurrence of number 2 in a range from 1 to 100

spir denis.spir at gmail.com
Sun Dec 1 10:57:40 CET 2013


On 12/01/2013 06:50 AM, Reuben wrote:
> Hi,
>
> How can we write a logic for detecting the number 2 in  range from 1 to 100

Do you mean:
	if 2 in numbers:
?

Also for a more general solution, think at the very nice function any(bools), in 
combination with a generator comprehension:

	numbers = [2,3,4,5,6,8]
	if any((n%2 == 1) for n in numbers):
	    print("some is odd")


More information about the Tutor mailing list