Python to pypy

I came to know that pypy is way faster than python and it’s syntax are almost similar. But when I had submitted this code it gave me error in pypy but not in pyth .Why is it so? And can someone please tell me where can i code for pypy?

import math
for test in range(int(input())):
 n=int(input())
 a=list(map(int,input().split()))
 t=sum(a)
 cc=0
 for i in range(0,len(a),2):
     cc=cc|(a[i] | a[i+1])
 print(min(t,cc))

The PyPy compiler on Codechef does not support Python 3. So your PyPy code should be a valid Python 2 code, but you are using Python 3 input() which is not the same as Python 2 input(). This is why you’re getting an error. You can replace input() with its Python 2 equivalent raw_input(), and your code should work since the rest of the code will be valid.

3 Likes

you can also consider:

import sys

from sys import stdin

a=list(map(int,sys.stdin.readline().strip().split(’’)))

In general, it is faster than just using raw_input()

2 Likes

Thanks a lot:)

1 Like

Thanks a lot:)