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
Define a function group-by-nondecreasing, which takes in a stream of numbers and outputs a stream of lists, which overall has th
Debora [2.8K]

Answer:

def group_by_nondecreasing( *args ) :

     num_list = [arg for arg in args]

     sorted_numlist = sorted( num_list )

     list_stream = [ sorted_numlist, sorted_numlist, sorted_numlist ]

     return list_stream

Explanation:

This python function has the ability to accept multiple and varying amount of arguments. the list comprehension shorten the logical for statement to generate a list of numbers, sorts the list in ascending order by default and duplicates the list in another list.

5 0
3 years ago
Write a menu-based program in C++ for an input restricted dequeue using Linked List consist of
Natali5045456 [20]

Answer:

C++ With Examples

— Input-restricted Deque: In input-restricted, deletion can be done from ... getLast: Retrieves the last item in the queue. ... Now, we insert element 3 at the rear.

8 0
2 years ago
How do I find a space in my String and replace it? JAVA
Fantom [35]

Answer:

This article shows how to use regex to remove spaces in between a String.

A string with spaces in between.

String text = "Hello World Java.";

We want to remove the spaces and display it as below:

Hello World Java.

1. Java regex remove spaces

In Java, we can use regex \\s+ to match whitespace characters, and replaceAll("\\s+", " ") to replace them with a single space.

Regex explanation.

`\\s` # Matches whitespace characters.

+ # One or more

StringRemoveSpaces.java

package com.mkyong.regex.string;

public class StringRemoveSpaces {

public static void main(String[] args) {

String text = "Hello World Java.";

String result = text.replaceAll("\\s+", " ");

System.out.println(result);

}

}

Output

Terminal

Hello World Java.

8 0
3 years ago
What is a mixer? BTW NOT just any mixer....a mixer in music<br> THis is for tech theater class
ASHA 777 [7]

Answer:

it changes the level of music, such as bass level or sweter level

6 0
3 years ago
Pressing the _____ key when entering title text in a placeholder creates a new paragraph. BACKSPACE SHIFT DELETE ENTER
Lunna [17]
Enter would create a new line, thus allowing you to enter a paragraph, on some applications you can use "Shift+Enter" if it is an IM application like Skype.
4 0
3 years ago
Other questions:
  • Which key removes all data from an active cell with one click
    7·2 answers
  • __ means having a current knowledge and understanding of computers, mobile devices, the web, and related technologies.
    8·1 answer
  • Create a function named first_a that uses a list comprehension. The function will take a single integer parameter n. Find every
    13·1 answer
  • Technician A says that front and rear U-joints on a RWD axle should operate at different angles to prevent vibration. Technician
    10·1 answer
  • 2
    11·1 answer
  • Compare and contrast the role that business users play when software is developed using Waterfall and Agile software development
    10·1 answer
  • 1. Write a generic method that compares its 2 arguments using the equals method and returns true if they are equal and false oth
    8·1 answer
  • How do you create a formula in excel​
    10·1 answer
  • Select the correct answer.
    15·1 answer
  • Why Use LinkedIn AI Automation Tools to Grow Your Sales Pipeline?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!