Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python In Exercise 7, you might have used split() or sort() to process the string. Notice that, like functions, they also have brackets attached to

Python

image text in transcribed

In Exercise 7, you might have used split() or sort() to process the string. Notice that, like functions, they also have brackets attached to them, but they are attached to the end of a variable with a dot. These are called methods in Python. They achieve similar results as functions, but are often faster at the expense of flexibility. See here for a discussion on stackoverflow about mylist.sort () vs sorted (mylist). a) Now use the IPython magic command time it to test which of the two is really faster in your notebook: testlist = [3, 0, 9, 2, 5] s time it sorted (testlist) timeit testlist.sort () (b) Use the Python built-in functions sum() and len() to make a function that calculates the average arithmetic mean) of a list of numbers: testlist = [3, 0, 9, 2, 5]. Then, use time it to test which one is the fastest: the function you wrote, the function mean() from the statistics module, the function mean() from the numpy module, and the method mean() from the same module. Which function/method is the fastest? (c) Test (b) again but with a much larger list/array of N = 10000 entries. You could use numpy.ones (N) or the good-old Python way of [1] *N to generate this big list. Which function/method is faster now? Note the similarity in syntax between module. function () and variable.method(). In both cases, the second object is an attribute of the first. A method is just an attribute of a variable, which has been defined to be a function that acts on the variable

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

Show the properties and structure of allotropes of carbon.

Answered: 1 week ago