subject

An inversion in a sequence is a pair of entries that are out of order. For example, the characters F and D form an inversion in the string 'ABBFHDL'. The characters H and D are also an inversion in the string 'ABBFHDL'. The total number of inversions in a sequence, i. e. the number of pairs that are out of order, is a measure of how unsorted the sequence is. Write a function inversions() that takes as a parameter a sequence of uppercase characters (i. e. a string with only uppercase letters) and returns the number of inversions in the sequence. The following shows the function on several sample parameters: def inversions(s):
count = 0
for i in range(len(s)): # for each index i
for j in range(len(s)): # for each index J
if s[j]>=s[i]: # compare string[i] and string[j]
count += 0
else:
count +=1
return count

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 05:20
Which operating system is a version of linux?
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Jace needs to answer a question on square roots to win a quiz. how can he use a spreadsheet to find the square root of 786? a. use the functions round and count b. create a table and chart c. use the function sqrt d. use the function now
Answers: 3
question
Computers and Technology, 23.06.2019 16:30
Which of the following is not an enhancement to the standard wiki to make it more attractive for corporations? encryptionwork spacespermission toolspredictive text
Answers: 2
question
Computers and Technology, 23.06.2019 18:50
Ais a picture icon that is a direct link to a file or folder
Answers: 1
You know the right answer?
An inversion in a sequence is a pair of entries that are out of order. For example, the characters F...
Questions
question
Geography, 31.01.2020 22:56