Question: Python =def pairs(alist): Return the number of times a pair occurs in a list. A pair is any two consecutive list elements that are equal.

Python
=def pairs(alist): Return the number of times a pair occurs in a list. A pair is any two consecutive list elements that are equal. The list may be empty or have only one element, in these two cases, return 0. Note: You will need a for Loop with an index because you need to access two different elements for each iteration # Test code assert (pairs([]) 0) assert (pairs(['a']) == 0) assert (pairs(['a', 'a']) := 1) assert (pairs(['a', 'a', 'a']) : 2) assert (pairs(['a', 'b', 'a', 'c', 'a']) == 0) assert (pairs([1, 1, 1]) == 2) assert (pairs(["one", "one", "two", "two"]) assert (pairs(["one", 2, 3 > 4, "one"]) == 0) == == 2)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
