Write a function count_clear (state) that takes a state of the cargo terminal, a
ID: 3587888 • Letter: W
Question
Write a function count_clear (state) that takes a state of the cargo terminal, and returns an integer count of the number of containers in the given state that are currently clear (i.e., have nothing stacked on top of them) Notes and assumptions: Note: The ground is not a container, so it doesn't count. . You can assume there are no duplicates. >>> count-clear ( [ [ ' c1' , ' c3' ] , e2 ' , ' ground ' ] , [ ' c3 ' , ' ground' ] ] ) 2 >>> count-clear ( [ [ ' c1' , ' c3' ] , [ ' c3 ' , ' c2' ] , [ ' c2' , ' ground ' ] ] ) 1 >count.clear (II'c4', 'ground'], ['c5', 'ground'], ['c6', 'ground']1)Explanation / Answer
def count_clear(state):
count = 0
for i in range(len(state)):
if len(state[i]) == 2:
if state[i][1] == "ground" :
count = count + 1
return count
print(count_clear([['c1','c3'],['c2','ground'],['c3','ground']]))
print(count_clear([['c1','c3'],['c3','c2'],['c2','ground']]))
print(count_clear([['c4','ground'],['c5','ground'],['c6','ground']]))