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
|
743 Discussions
|
Please Login in order to post a comment
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?
My first submission used
if __name__ in "__main__":
as I was used to another system where that was a requirement in solution files or the test didn't run. The third line with the print was over 110 characters.Once I realized my line 1 wasn't required I got it down to two lines. Then I refined it further and renamed numbers to nums so second line would be less than 80 characters total.
N = int(input())
input_list = list(map(int,input().split()))
print(len(input_list)==N and all(x>=0 for x in input_list) and any(str(x)==str(x)[::-1] for x in input_list))