1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
BlackZzzverrR [31]
3 years ago
13

write a python function that takes the largest and smallest numbers in a list, and swap them (without using min() or max() )

Computers and Technology
1 answer:
Akimi4 [234]3 years ago
8 0

Answer:

def SwapMinMax ( myList ):

   myList.sort()

   myList[0], myList[len(myList)-1] = myList[len(myList)-1], myList[0]

   return myList

   

Explanation:

By sorting the list, you ensure the smallest element will be in the initial position in the list and the largest element will be in the final position of the list.

Using the len method on the list, we can get the length of the list, and we need to subtract 1 to get the maximum element index of the list.  Then we simply swap index 0 and the maximum index of the list.

Finally, we return the new sorted list that has swapped the positions of the lowest and highest element values.

Cheers.

You might be interested in
An ipv4 address in the range 169.254.0.1 through 169.254.255.254 indicates a problem with what type of service
DENIUS [597]

Dynamic Host Configuration Protocol, also known as DHCP.

3 0
3 years ago
To change the backround color of a page, which tab would you use?
ivann1987 [24]
I have concluded the answer is a
4 0
3 years ago
Read 2 more answers
What activities are the most likely to infect your computer with a virus? Check all that apply
Alex17521 [72]
Opening unfamiler emails and visiting unknown websites
4 0
4 years ago
Read 2 more answers
You create a database that stores data in tables that consist of rows and columns. each row has a primary key, and each column h
jeyben [28]
The answer is a relational database.

A data model in database management system consists of rules that define how the DB organizes data. Today, a relational database is widely used. It is a collection of data items organized as a set of formally described tables from which data can be accessed in many different ways.



3 0
3 years ago
Read 2 more answers
Which binary number is equivalent to the decimal number 104?
ra1l [238]

B. 01101000

For future reference you can look up decimal to binary calculators online; or binary to decimal.

6 0
3 years ago
Other questions:
  • On a DTP project, Morgan is preparing digital files to be sent to a printer. Which word describes the activity that Morgan is pe
    5·2 answers
  • which of the following are used on cable trays to protect the cable insulation from direct sunlight? a. barrier strips b. solid
    5·1 answer
  • Tell me about how to build robots
    11·1 answer
  • Explain Cascading Style Sheets and what they do. Describe their primary function, two effects that this function has on programm
    11·1 answer
  • "When you can control devices and appliances by apps installed on your smartphone or tablet, you are said to have"
    6·1 answer
  • Ladders are a fundamental piece of equipment on construction sites and employers are expected to ensure that workers follow safe
    5·1 answer
  • If all the data in a database is not physically located in one place, it would be a(n _______ database.
    5·1 answer
  • 10. What is "bandwidth"? (
    15·1 answer
  • The 10 and 2 o'clock hand position on the steering wheel is no longer recommended because _____.
    13·1 answer
  • True or False. A Windows Server 2016 that was installed in Desktop Experience mode can be converted to Server Core mode.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!