Header Ad

HackerRank Any or All problem solution in python

In this Any or All problem, You are given a space-separated list of integers. If all the integers are positive, then you need to check if an integer is a palindromic integer.

HackerRank Any or All solution in python


Problem solution in Python 2 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
def is_pal(n):
    S=str(n)
    return all((s==t for s,t in zip(S,reversed(S))))
def meets_conditions(L):
    if not all((l>0 for l in L)):
        return False
    return bool(any((is_pal(l) for l in L)))

N=int(raw_input())
L=map(int, raw_input().split())
print meets_conditions(L)



Problem solution in Python 3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
N,n = int(input()),input().split()
print(all([int(i)>0 for i in n]) and any([j == j[::-1] for j in n]))


Problem solution in pypy programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
N,n = input(),raw_input().split()
print all([int(i)>0 for i in n]) and any([j == j[::-1] for j in n])


Problem solution in pypy3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
n = int(input())
a = list(input().split())
if all(int(x)>0 for x in a) and any(x ==x[::-1] for x in a):
    print ('True')
else: 
    print('False')


Post a Comment

0 Comments