Covert Java to python

Anyone can convert this to python?

public static int findLargest(Integer insertedDigit, Integer startValue){
StringBuffer sb = new StringBuffer(startValue.toString());
int length = sb.length();
List allCombinations = new ArrayList<>();
for(int i = length; i >= 0; i–) {
// inserts the digit 5 at a different index for every iteration
sb.insert(i, insertedDigit);
// adds the new number to a list that contains all various combinations
allCombinations.add(Integer.parseInt(sb.toString()));
// resets the StringBuffer instance to the initial value
sb = new StringBuffer(startValue.toString());
}
System.out.println(allCombinations); // prints out [6705, 6750, 6570, 5670]
Collections.sort(allCombinations, Comparator.reverseOrder());
return allCombinations.get(0); // returns the largest number: 6750
}

That looks a lot like coursework which I’d rather not do for you, but if you have trouble with specific things I’d be happy to help, and I’m sure some others too. Just ask questions! :wink:

As a side note, please use code blocks (enclosed in triple backticks, like “```”) for posting code. That preserves indentation, which always helps readability and is critical for Python.

2 Likes