1
I have a dictionary inside the list:
A dictionary can be used to provide a "dependency table". For example, dependencies of disciplines in college.
To do Calculus 3, I first need to do Calculus 2 and Vectors.
To do Calculus 2, I first need to do Calculus 1.
For Calculation 1, there is no prerequisite.
To do Vectors, there is no prerequisite.
This can be represented by the following dictionary:
dependencies = { 'calculus 3' ['calculus 2', 'vectors'] 'calculus 2' ['calculus 1'] }
(Disciplines without dependency need not be cited.)
Note that, in total, calculation 3 ends up having THREE effective prerequisites: calculation 1, calculation 2 and vectors.
This is because calculation 1 is not cited directly but is indirect requirement.
I need to create a function that shows this DIRECT dependency: I thought of something like this:
def mostra_dependencias_diretas(dicionario, materia):
for chave, valor in dicionario.items():
if chave == materia:
print(valor)
def test_06_dependencias_diretas(self):
simples = {
'calculo3' : ['calculo2', 'vetores'],
'calculo2' : ['calculo1']
}
s1 = pega_saida(mostra_dependencias_diretas, simples, 'calculo3')
self.assertEqual(sorted(s1.split()), ['calculo2', 'vetores'])
mas o meu esta assim:
AssertionError: Lists differ: ["'vetores']", "['calculo2',"] != ['calculo2', 'vetores']
But what is the doubt? How to make a function to list indirect dependencies?
– Andre
the method to list the directories is not working.
– Darcy
I took the test here and except for the print indentation error, it seems to be all right. It was supposed to be printing another result?
– Andre
This is the question https://answall.com/questions/419580/fun%C3%A7%C3%a3o-que-recebe-um-dicionario are the same.
– Augusto Vasques
if I do the test: simple = { 'calculo3' : ['calculo2', 'vectors'], 'calculo2' ['calculo1'] } It should be self.assertEqual(Sorted(S1.split()), ['calculo2', 'vectors']), but I’m wrong: Assertionerror: Lists differ: ["'vectors']", "['calculo2',"] != ['calculus 2', 'vectors']
– Darcy