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 15:10
David is in week 3 of his current ashford course and has a paper due by monday night at midnight. he has finished everything but the concluding paragraph. as he boots up his computer to work on it, he sees a flash across the screen and then the screen goes black. he begins to panic as he tries desperately to turn the laptop back on. david should have saved his work on what kind of portable device?
Answers: 2
question
Computers and Technology, 22.06.2019 22:00
Discuss the ways in which electronic information associated with payments is addressed in terms of security. include encryption, secure sockets layers, and secure electronic transactions in your discussion. are there any other ways that consumers and businesses can keep their payment information secure in an electronic commerce environment? do you feel that your information is safe when conducting electronic business? why or why not?
Answers: 1
question
Computers and Technology, 23.06.2019 14:00
Select the correct answer. a company is currently focusing on creating specific management goals for itself. which level of maturity is the company demonstrating under the sse_ccm framework? a. performed informally b. planned and tracked c. quantitatively controlled d. well-defined e. continuously improving
Answers: 2
question
Computers and Technology, 23.06.2019 22:50
What is an rss reader used for? for creating a user account on a social new site
Answers: 2
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
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Social Studies, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
English, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Social Studies, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
English, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
Questions on the website: 13722362