Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following function takes a list arglist and returns a pair of lists, evens and odds , such that evens consists of the elements at

The following function takes a list arglist and returns a pair of lists, evens and odds, such thatevens consists of the elements at even-numbered positions of arglist, i.e., arglist[0],arglist[2], etc.; and odds consists of the elements at odd-numbered positions of arglist, i.e., arglist[1], arglist[3], etc.

def odds_and_evens(arglist): evens = [] odds = [] for i in range(len(arglist)): ith_element = arglist[i] if i % 2 == 0: evens.append(ith_element) else: odds.append(ith_element) assert list_lengths_ok_after_loop(arglist, evens, odds) return (evens,odds) 

Write a functionlist_lengths_ok_after_loop(arglist, evens, odds) that will be called by the assert after the loop has finished execution and before the function returns. The purpose of this function is to check that the lengths of the two lists evensand odds are the right values.

Your functionlist_lengths_ok_after_loop(arglist, evens, odds) should behave as follows. Given:

arglist: the list being split into even- and odd-position lists;

evens and odds: the lists of even- and odd-position elements of arglist, respectively, after the execution of the loop;

returns:

True if the lists evens and odds are each of the right length.

False otherwise.

Programming Requirements

The function specified above should be implemented without using an if statement; also, you must not use a while or for loop. You can use the Boolean operators and, or, and not.

Note that solutions that "accidentally" pass test cases will not get credit.

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

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions