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, 22.06.2019 21:50
Given int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total. thus your code should put 11 + 22 + 33 + + 4949 + 50*50 into total. use no variables other than k and total.
Answers: 2
question
Computers and Technology, 23.06.2019 02:30
Research data that is presented using descriptive language is said to be
Answers: 2
question
Computers and Technology, 23.06.2019 03:30
Many everyday occurrences can be represented as a binary bit. for example, a door is open or closed, the stove is on or off, and the fog is asleep or awake. could relationships be represented as a binary value? give example.
Answers: 1
question
Computers and Technology, 23.06.2019 14:30
Open this link after reading about ana's situation. complete each sentence using the drop-downs. ana would need a minimum of ato work as a translator. according to job outlook information, the number of jobs for translators willin the future.
Answers: 3
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
English, 25.06.2019 12:30