We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Built-Ins
- Any or All
- Discussions
Any or All
Any or All
Sort by
recency
|
745 Discussions
|
Please Login in order to post a comment
n , arr = int(input()) , input().split() print(all(int(x)>0 for x in arr) and any(x == x[::-1] for x in arr))
Here's what I used:
pyp3 answer
N=int(input()) li=list(map(int,input().split(" "))) if (all(i>0 for i in li)==True) and (any(str(i)[::-1]==str(i) for i in li)==True): print(True) else: print(False)
n = input() number_list = tuple(map(int, input().split())) print(all(number>=0 for number in number_list) and any(str(number) == str(number)[::-1] for number in number_list))
How come input 1 and 81 test case returns False, 81 is postive number and 1 is palindrome then it supposed to return True. My test case is failing as expected output is False for the above input 1 and 81 but my program returns True. Any suggestions?
The task description is confusing! To be True, ALL numbers must be positive, plus AT LEAST ONE (i.e. any()) number must be palindromic. The example demonstrates it better, but it's still not the clearest or easiest to follow. I initially read it that it didn't require all numbers to be positive, just that any positive numbers were all palindromic.