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...

  • 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.

  • Python Consider we have two List SL1 and SL2 representing a Set of integers. Write a...

    Python Consider we have two List SL1 and SL2 representing a Set of integers. Write a functionusing PYTHON intersectionSet(SL1, SL2) to create a third set SL (technically a List representing a set) which is the set-theoretic intersection of two initial existing lists . (i.e Only elements that are members of both input lists are copied into the third set). The function should return the resulting set.

  • write in python Create a program that will ask the user for a list of integers,...

    write in python Create a program that will ask the user for a list of integers, all on one line separated by a slash. construct a list named "adj_numbers" which contains the users input numbers after subtracting 2 from each number. then print the resulting list. the input statement and print statement are given to you in the starting code. a sample run of the program is as follows: Enter a list of integers, separated by slashes: 7/3/6/8 resulting list:...

  • with python Write a function called linear_search which consumes a sorted list of integers and a...

    with python Write a function called linear_search which consumes a sorted list of integers and a number and linearly searches for the number in the list. Your function should return how many comparisons were made in order to find the element in the list. If the element is not in the list, your linear search should return -1 For example:

  • This program should use a main function and two other functions named playlist and savelist as...

    This program should use a main function and two other functions named playlist and savelist as follows: The main function: The main function should create an empty list named nums and then use a loop to add ten integers to nums, each integer in the range from 10-90. NOTE: In Python, a list is a data type. See Chapter 7. The main function should then call the playlist function and savelist function, in that order. Both of these functions take...

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
ADVERTISEMENT