There doesn't seem to be a way to write this type of for loop in Python because I'm trying to translate/rewrite this javascript code into Python. How do I set the inital loop index like j in the nested loop?
Here's my JS code:
// Write a function called findGreaterNumbers which accepts an array and returns the number of times a number is followed by a larger number.
// Examples:
// findGreaterNumbers([1,2,3]) // 3 (2 > 1, 3 > 2, and 3 > 1)
// findGreaterNumbers([6,1,2,7]) // 4
// findGreaterNumbers([5,4,3,2,1]) // 0
// findGreaterNumbers([]) // 0
function findGreaterNumbers(arr) {
let count = 0
for (let i= 0; i < arr.length; i++){
for (let j= i + 1; j < arr.length; j++){
if(arr[j] > arr[i]){
count++;
}
}
}
return count;
}