Question

Suppose nums is a list of integers. Provide two Python statements that, together, would put it...

Suppose nums is a list of integers. Provide two Python statements that, together, would put it in order from largest to smallest?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer

nums = sorted(nums)
nums = list(reversed(nums))

Testing this in a full python program

nums = [3, 9, 1, 7]

nums = sorted(nums)
nums = list(reversed(nums))

print(nums)

[9, 7, 3, 1] Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
Suppose nums is a list of integers. Provide two Python statements that, together, would put it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #PYTHON In this exercise your function will receive three parameters, a list of integers, and two...

    #PYTHON In this exercise your function will receive three parameters, a list of integers, and two integers. It will add up all values in the list that are inside of the range of the two integers. Parameters: nums, a , b Return Value: A total found by adding all values in nums which are greater than a and less than b.

  • Python: problem 1 Given an array of integers, return the sum of two indices from this...

    Python: problem 1 Given an array of integers, return the sum of two indices from this array based on input parameters, x and y. Example: Given nums = [2, 7, 11, 15], x = 3, y = 1 Because nums[x] + nums[y] = 15 + 7 = 22, return 22. You may use this as a template for your code class Solution: def two_sum(self, nums: List[int], x: int, y: int) -> int:

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • Suppose your program already has a list called nums, which contains several numbers. Write a for...

    Suppose your program already has a list called nums, which contains several numbers. Write a for loop that will update every value in nums to be three times as big as it was before. (In Python)

  • Python Write a function named minGap that takes in a list of integers and returns the...

    Python Write a function named minGap that takes in a list of integers and returns the minimum ‘gap’ between values in the list. The gap between two adjacent values in a list is defined as the second value minus the first value. For example, suppose we have the following list: [1, 3, 6, 7, 12] The first gap is between indices 0 and 1 and its value is 3 − 1 = 2. The second gap is 6 − 3...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • In C++: Write a program that reads a list of integers, and outputs the two smallest...

    In C++: Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The list is preceded by an integer indicating how many numbers are in the list. If the input is: 5 10 5 3 21 2, the output is: 2 3 To achieve the above, first read the integers into a vector.

  • Using Python. Write a function clean2(aList) that takes a list of integers aList as argument, and...

    Using Python. Write a function clean2(aList) that takes a list of integers aList as argument, and modifies this list, such as multiple occurrences of values have been removed. The procedure does not return a list: it modifies its argument (reference aList). 3 For instance, the following statements: al = [1,2,3,4,4,4,5,1,2,1,5] print(al) clean2(al) print(al) print the following result (a different order of values is acceptable): [1,2,3,4,4,4,5,1,2,1,5] [1,2,3,4,5]

  • Python Suppose we have a list x = [43,34,22,32,62,12]. Write a Python program to figure out...

    Python Suppose we have a list x = [43,34,22,32,62,12]. Write a Python program to figure out the smallest number in the list without using the min() function. Hint: You can use an arbitrary large number as the temporary smallest number to start the program. Such as temp_smallest = 100.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT