algorithm - What does stack[-1] mean in a pseudocode? -


def _all_simple_paths_graph(g, source, target, cutoff=none): if cutoff < 1:     return visited = [source] stack = [iter(g[source])] while stack:     children = stack[-1]     child = next(children, none)     if child none:         stack.pop()         visited.pop()     elif len(visited) < cutoff:         if child == target:             yield visited + [target]         elif child not in visited:             visited.append(child)             stack.append(iter(g[child]))     else: #len(visited) == cutoff:         if child == target or target in children:             yield visited + [target]         stack.pop()         visited.pop() 

i find code on link.

but did not understand statements, following

  • children = stack[-1] // stack[-1] mean?

  • child = next(children, none) // child list or children list?

  • stack = [iter(g[source])] // iter?

  • if child none: // guess if child empty (child list).

  • visited = [source] // that?

  • yield visited + [target] // yield?

can explain me? trying rewrite in c.

it looks python code


1) stack[-1] means give last element.
2) children variable, code holds last element of list stack

children = stack[-1] 

child whatever next() function returns, looks of it, looks variable.


4) if child none: if next() function returns none


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -