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

  • Home
  • SEARCH
  • 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 7164547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:05:35+00:00 2026-05-28T14:05:35+00:00

for a in map: for b in map[a]: for c in map[b]: for d

  • 0
for a in map:
    for b in map[a]:
        for c in map[b]:
            for d in map[c]:
                for e in map[d]:
                    print a+b+c+d+e

The above code is used to create all paths of certain length in a graph.
map[a] represents the points you can reach from point a.

How can I change it to simulate having an arbitrary number of loops?

This is like a cartesian product (itertools.product) where at each iteration
your choice for the next element is limited to those in map[current_point].

  • 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-28T14:05:36+00:00Added an answer on May 28, 2026 at 2:05 pm
    map = {
        'a': ['b', 'c'],
        'b': ['c', 'd'],
        'c': ['d', 'a'],
        'd': []
    }
    
    def print_paths(map, start, length, prefix = ''):
        if length == 0:
            print prefix
        else:
            for a in map[start]:
                print_paths(map, a, length - 1, prefix + start)
    
    for a in map.keys():
        print_paths(map, a, 5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a subscriber on a map. here is the code:
Consider the following code. I want to specialize std::hash<> used in a Map ,
Not really getting the point of the map function. Can anyone explain with examples
Can anyone point me in the right direction on how to map a route
Can anyone point me out, how can I parse/evaluate HQL and get map where
EDIT: thanks a lot for all the answers an points raised. As a novice
In the following code, the last phrase I can put an in in front.
The following code is supposed to find the key 3.0 in a std::map which
I have a custom marker on my map, and an image above the maps,
Hi suppose I want to create a map of the form map<int, vector<node> >

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.