Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lists of even integers 1 / 4 This problem has you write a nested loop to process a list of list of int, and accumulate

Lists of even integers
1/4
This problem has you write a nested loop to process a list of list of int, and accumulate a list of list of int. The starter code provides an accumulator for the result and a loop over the lists, and you need to write the code that checks whether sublist contains only even ints.
You'll probably want a one-way flag: a Boolean variable that starts out as True and is set to False if you find an odd int in the sublist. You'll need to check the value of this variable to figure out whether to append sublist to the even_lists accumulator.
def only_evens(lst: list[list[int]])-> list[list[int]]:
"""Return a list of the lists in lst that contain only even integers.
>>> only_evens([[1,2,4],[4,0,6],[22,4,3],[2]])
[[4,0,6],[2]]
"""
even_lists =[]
for sublist in lst:
# write your code here (please read above for a suggested approach)
return even_lists

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions