Page 1 of 1

Problem 6 - listlib.pairs() [10 points] Define a function listlib.pairs () which accepts a list as an argument, and retu

Posted: Sat May 14, 2022 7:02 pm
by answerhappygod
Problem 6 Listlib Pairs 10 Points Define A Function Listlib Pairs Which Accepts A List As An Argument And Retu 1
Problem 6 Listlib Pairs 10 Points Define A Function Listlib Pairs Which Accepts A List As An Argument And Retu 1 (104.13 KiB) Viewed 40 times
Problem 6 - listlib.pairs() [10 points] Define a function listlib.pairs () which accepts a list as an argument, and returns a new list containing all pairs of elements from the input list. More specifically, the returned list should (a) contain lists of length two, and (b) have length one less than the length of the input list. If the input has length less than two, the returned list should be empty. Again, your function should not modify the input list in any way. For example, the function call pairs(['a', 'b', 'c']) should return [['a', 'b'], ['b', 'c']], whereas the call pairs (['a', 'b']) should return [['a', 'b']], and the calls pairs (['a']) as well as pairs ([]) should return a new empty list. To be clear, it does not matter what the data type of ele- ments is; for example, the call pairs ([1, 'a', ['b', 2]]) should just return [[1, 'a'], ['a', ['b', 2]]