📅  最后修改于: 2023-12-03 15:00:46.162000             🧑  作者: Mango
first_last6
- Pythonfirst_last6
is a Python function that takes in a list of integers and returns True
if the first or last integer in the list is 6, and False
otherwise.
def first_last6(nums: List[int]) -> bool:
nums
: A list of integers. (required)True
if the first or last integer in the list is 6, and False
otherwise.from typing import List
def first_last6(nums: List[int]) -> bool:
if nums[0] == 6 or nums[-1] == 6:
return True
else:
return False
# Testing
print(first_last6([1, 2, 6])) # True
print(first_last6([6, 1, 2, 3])) # True
print(first_last6([13, 6, 1, 2, 3])) # False
first_last6
function takes a list of integers nums
as input.True
.False
.True
, because the lists contain a 6 in the appropriate position. The third test returns False
because there is no 6 at the beginning or end of the list.