0
Let’s simulate a queue situation at the bus terminal. Write a function that receives a NAME LIST (strings) that indicates the order of arrival of people to catch a bus from the terminal.
Your role should create a queue and insert people into it in order of arrival (the order in which they appear in the received list as a parameter).
Caution: there is a passenger, called Samuel, who caused problems in the terminal yesterday. Today, the inspector will stop you from boarding, so that he pays clarifications.
IE: you will add the names in the queue, but you should ignore the Samuel, who is not allowed to embark.
Then, removing one by one from the queue, create a new list that shows the order where people will get on the bus.
Your function will, at the end, return the boarding list.
Examples are: embarca(['Jose', 'Henrique', 'Carla']) --> returns the list [ 'Jose', 'Henrique', 'Carla' ], indicating the order of embarkation.
embarks(['Jose', 'Samuel', 'Carla']) --> returns the list ['Jose', 'Carla']
class Fila:
def __init__(self):
self.fila = deque() # atributo fila é um objeto do tipo deque
def insere(self, novo):
self.fila.append(novo) # uso append para inserir no final
def remove(self):
return self.fila.popleft() # popleft remove da esquerda (início)
def tamanho(self):
return len(self.fila) # usa len para calcular tamanho da fila
def vazia(self):
if len(self.fila) == 0:
return True
else:
return False
fila = Fila()
def embarca(pessoas):
lista = []
for i in range(len(pessoas)):
if i != "Samuel":
fila.insere(i)
c = fila.remove()
lista.append(c)
return lista