Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 534545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:37:25+00:00 2026-05-13T09:37:25+00:00

I have an unusual tree array like this: [[0, 1], [1, 2], [2, 3],

  • 0

I have an unusual tree array like this:

[[0, 1], [1, 2], [2, 3], [2, 4], [2, 5], [5, 6], 
 [4, 6], [3, 6], [0, 7], [7, 6], [8, 9], [9, 6]]

Each element of the array is a pair, which means second one is a follower of the first, e.g.:

[0, 1] - 0 is followed by 1
[1, 2] - 1 is followed by 2

I am trying to extract array like this:

0 1 2 3 6    
0 1 2 4 6    
0 1 2 5 6
0 7 6
8 9 6

I couldn’t code a robust traversal to extract all possible paths like this. How can I do it with Python?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:37:26+00:00Added an answer on May 13, 2026 at 9:37 am

    Here you go. Not the nicest code on earth but it works:

    inputValues = [[0, 1], [1, 2], [2, 3], [2, 4], [2, 5], [5, 6], [4, 6], [3, 6], [0, 7], [7, 6], [8, 9], [9, 6]]
    
    tree = {}
    numberOfChildren = {}
    for (f, t) in inputValues:
      if not tree.has_key(f):
        tree[f] = []
      tree[f].append(t)
      if not numberOfChildren.has_key(t):
        numberOfChildren[t] = 0
      numberOfChildren[t] += 1
    
    roots = [c for c in tree if c not in numberOfChildren]
    permutations = []
    
    def findPermutations(node, currentList):
      global tree
      global permutations
      if not tree.has_key(node):
        permutations.append(currentList)
        return
      for child in tree[node]:
        l = list()
        l.extend(currentList)
        l.append(child)
        findPermutations(child, l)
    
    for r in roots:
      findPermutations(r, [r])
    
    print permutations
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an unusual need. I have five input checkboxes that look like this:
I have an array of structs. Actually, it is a 2d-array but an unusual
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
This is maybe unusual so let me set the scene: We have an SVN
I have an unusual use-case I'm trying to code for. The goal is this:
Hello I have an unusual date format that I would like to parse into
Salute.. I have an unusual problem. Here in this table in MSDN library we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.