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]
2 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]2 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
Compress<br> 00eb:0000:0000:0000:d8c1:0946:0272:879<br> IPV6 Address
ikadub [295]

Answer:

Compress

00eb:0000:0000:0000:d8c1:0946:0272:879

IPV6 Addres

Explanation:

3 0
3 years ago
________ are used in input, processing, and output operations that can help create more efficient programs as the data can be pr
lapo4ka [179]
Functional requirements <span>are used in input, processing, and output operations that can help create more efficient programs as the data can be processed many times without having to be input again.
</span>The functional requirements define function/s of a system or its component. It <span>describes what a software system should do.</span>
8 0
3 years ago
Ayuda por favor.<br><br>Please help!!
rewona [7]

Answer:

I know you're going to delete my answer... But I have an essay which needs to be completed online and I need to ask a urgent question!

If you have a better reason WHY you need me to answer the RIGHT answer... Please reply.

Explanation:

8 0
2 years ago
What does txt atm mean? what does txt atm mean
Stolb23 [73]
I think it means text
3 0
3 years ago
What should you do if your temperature gauge moves up to just below the red zone?
Alexeev081 [22]
<span>If the temperature gauge moves up to just below the red zone,you should turn off your air conditioner and turn on your vehicle's heater. Then immediately </span>find a mechanic or pull over safely and contact a road service.




4 0
3 years ago
Read 2 more answers
Other questions:
  • How do you take a screenshot on an iPhone?
    8·2 answers
  • We never need to use a forward declaration when invoking a public subprogram. true or false?
    15·1 answer
  • What is the assignment operator?
    15·1 answer
  • The chemical symbol H represents which of the following elements?
    9·2 answers
  • List of most popular entertainment and culture websites
    15·1 answer
  • After completion of this chapter, you should be able to:  Describe the structure of an IPv4 address.  Describe the purpose of
    5·1 answer
  • Write a program in which given an integer num, return the sum of the multiples of num between 1 and 100. For example, if num is
    7·1 answer
  • Theodor is researching computer programming. He thinks that this career has a great employment outlook, so he'd like to learn if
    9·2 answers
  • The identification of the technology management framework contain?
    6·1 answer
  • Create a vector of structures experiments that stores information on subjects used in an experiment. Each struct has four fields
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!