Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

screen Shot 2018-03-09 at 8.12.34 uestion 1: (a) For each task below, write a one-line expression using Python functions to yield the result (no comprehension).

image text in transcribed
screen Shot 2018-03-09 at 8.12.34 uestion 1: (a) For each task below, write a one-line expression using Python functions to yield the result (no comprehension). The simpler your code the better. (3 marks) Retrieve the n largest items from a list or a tuple of numbers 1t n,1t= 3,[1,6,3,11,14 , 7,0,2,19,10] e.g., -> [11,14,19] Create a new string with the words of string s in reverse order e.g., s 'dog bird cow ant' -> 'ant cow bird dog' Add all the comma-separated numbers in a string e.g., s= "1.7, 5 , 3.3" -> 10 (b) Use Python comprehension to realize each of the tasks below. (3 marks) -Create a list of all the divisors of a given number n (excl. i and n) e.g., n = 99-> [3, 9, 11, 33] - Create a list of the squares of the numbers in list 1, discarding non-numbers eg. I = [2, 'str', {}, 35/5, int(5'), (3#2.), 10] 100] -> [4, 49.0, 25, Create a list of unique triples (a, b , c) such that a4b2=c2, osa , b , CSN. e.g., N= 16-> [(3,4,5), (5,12,13), (6,8,10), (9,12,15)]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students explore these related Databases questions