如何将Java代码转换成python代码
Java代码:
import java.util.*;
public class Main
{
public static void main(String[] args)
{
List<Integer> a = new ArrayList<Integer>(Arrays.asList(3, 2, 1, 7, 344, -2, -3));
removeEvens(a, 0);
System.out.println(a);
}
private static void removeEvens(List<Integer>a, int index) {
if(index < a.size())
if(a.get(index) % 2 == 0)
{
a.remove(a.get(index));
removeEvens(a, index);
}
else
removeEvens(a, index +1);
}
}
Python代码,我无法调用里面的removeEvens, 在粗体星号部分显示报错:
class Main:
def main(self):
a =(3,2,1,7,344,-2,-3)
**removeEvens(a, 0)**
print(a)
def removeEvens(a, index):
if(index < a.size()):
if(a.get(index) %2 ==0):
a.remove(a.get(index))
**removeEvens(a, index)**
else:
**removeEvens(a, index+1)**
Main().main()