For each of the tasks below write a oneline Python expressio
For each of the tasks below, write a one-line Python expression that will achieve the result. Code the Python way; the simpler, the better. -Retrieve the n largest items from a list or a tuple of numbers 1t e.g., n, 1t = 3, [1, 6, 3, 11, 14, 7, 0, 2, 19, 10] rightarrow [11, 14, 19] Create a new string with the words of string s in reverse order e.g., s = \'dog bird cow ant\' rightarrow \'ant cow bird dog\' -Add all the comma-separated numbers contained in a string e.g., s= \"1.7, 5, 3.3\" rightarrow 10 Use list comprehension to realize each of the tasks below. -Create a list of all the divisors of a given number n (excl. 1 and n) e.g., n = 99 rightarrow [3, 9, 11, 33] -Create a list of cubes of the numbers in list 1, discarding non-numbers e.g., 1 = [(), 2, \'tr\', (4-7j), int(\'5\'), 22//3, (3**2), 10] rightarrow [8, 125, 343, 729, 1000] -Create a list of unique triples (a, b, c) such that a^2+b^2=c^2, 0 lessthanorequalto a, b, c lessthanorequalto N. e.g., N = 16 rightarrow [(3, 4, 5), (5, 12, 13), (6, 8, 10), (9, 12, 15)]
Solution
a)
take a list or tuple and then use sort function
for example
list={1,2,3,4,5,6}
------------
for example string s= \'hello world\';
dlrow oleh
--------------------------
initially use split function to convert it to a list and then add the elements in the list
s.split(\' \') //it will onvert the string into list
2)
def print_factors(n):
print(\"The factors of\",n,\"are:\")
for i in range(1, n + 1):
if n % i == 0:
print(i)
num = 320
print_factors(num)
------------------------------------------
