python3 (1a) Complete the examples in the docstring and then write the body of t
ID: 3724719 • Letter: P
Question
python3
(1a) Complete the examples in the docstring and then write the body of the following function: def diff_first_last(L):
'’' (list) -> boolean Precondition: len(L) >= 2
Returns True if the first item of the list is different from the last; else returns False.
>>> diff_first_last([3, 4, 2, 8, 3])
False
>>> diff_first_last(['apple', 'banana', 'pear'])
??
>>> diff_first_last([4.0, 4.5])
?? '''
(1b) Add two more examples/test cases to the docstring of diff_first_last and indicate why they are useful test cases.
Explanation / Answer
def diff_first_last(arr):
if arr[0] == arr[ len(arr) - 1 ]:
return False
return True
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.