Question: Exercise 1 Complete exercise 1 from Section 10.15 of the textbook. Write a function called nested_sumthat takes a list of lists of integers and adds

Exercise 1

Complete exercise 1 from Section 10.15 of the textbook.

Write a function called nested_sumthat takes a list of lists of integers and adds up the elements from all of the nested lists. For example:

>>> t = [[1, 2], [3], [4, 5, 6]] >>> nested_sum(t) 21 

Exercise 2

Write a function called count_matches that takes a list of strings, and outputs the number where the string length is 2 or more, and the first and last character of the string match each other.

Sample List : ['abc', 'xyz', 'aba', '1221'] Expected Result : 2

Exercise 3

Write a function that implements the Sieve of Eratosthenes (Links to an external site.)to find all the prime numbers between 1 and a given number n.

In "pseudo-code", here is an algorithm from Wikipedia that you can convert into Python. In Python, you can simply have a list of primes which starts empty and is then added to rather than bothering with Boolean values.

algorithm Sieve of Eratosthenes is input: an integer n > 1. output: all prime numbers from 2 through n. let A be an list of Boolean (Links to an external site.) values, indexed by integers 2 to n, initially all set to true. for i = 2, 3, 4, ..., not exceeding n do if A[i] is true for j = i2, i2+i, i2+2i, i2+3i, ..., not exceeding n do A[j] := false return all i such that A[i] is true.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!