python
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]]
Problem 6 - listlib.pairs() [10 points] Define a function listlib.pairs () which accepts a list as an argument, and retu
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Problem 6 - listlib.pairs() [10 points] Define a function listlib.pairs () which accepts a list as an argument, and retu
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!