Skip to content

Instantly share code, notes, and snippets.

@thbighead
Created April 17, 2017 02:48
Show Gist options
  • Save thbighead/e4fcd0b7f95d88e3fd5a0056648fc399 to your computer and use it in GitHub Desktop.
Save thbighead/e4fcd0b7f95d88e3fd5a0056648fc399 to your computer and use it in GitHub Desktop.
Calcular a transposicao de um digrafo feito com Python
def transpor_digrafo(digrafo):
digrafo_t = {}
for vertice in digrafo:
digrafo_t[vertice] = []
for vertice in digrafo:
for vizinho in digrafo[vertice]:
digrafo_t[vizinho].append(vertice)
return digrafo_t
digrafo = {
'a': ['c', 'd', 'f'],
'b': ['a'],
'c': ['b'],
'd': ['e', 'f'],
'e': [],
'f': ['e']
}
print transpor_digrafo(digrafo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment