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 4097144
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:08:10+00:00 2026-05-20T20:08:10+00:00

i’m going nuts here with this and i have a deadline. So i have

  • 0

i’m going nuts here with this and i have a deadline. So i have this multi-d list in python:

list_a = [[['a', 'b'],['c', 'd'], ['e', 'CB'], ['g', 'h'], ['a', 'j', 'k']]]

Notice, that the whole thing is in 2 brackets.
I need to compare elements like this: a to c, a to d, b to c, b to d, a to e, a to CB…until the first list has compared all it’s items with all the items in the other lists, then it moves on to the second list and starts comparing its items to the rest of the lists and so on till the end. I don’t want it to compare its own items to its own list.
Here’s some code:

for i in range(0, len(list_a)):
  for j in range(0, len(list_a)):
    for o in range (0, len(list_a[i])):
        for t in range(1, len(list_a[j])):
            try:
                for x in range(0, len(list_a[i][o])):
                    for y in range(0, len(list_a[j][t])):
                        print list_a[i][o][x], "i=",i, "o=",o, "x=",x
                        print list_a[j][t][y], "j=",j, "t=",t, "y=",y
            except IndexError:
                print ""

This one fails cause it compares its own items to its own items. Surely there’s a better way to do this rather than putting a lot of forloops inside each other.

And also, i need it to signal me, when it encounters CB. This would be easy if it looped right. Oh, and that “try” over there can be removed i guess. I’m sure this is easy as pie, but i just can’t figure it out right now.

  • 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-20T20:08:10+00:00Added an answer on May 20, 2026 at 8:08 pm

    You can use itertools to get all pairs from a list and then find all products of them:

    import itertools
    for l1, l2 in itertools.combinations(list_a[0], 2):
        for e1, e2 in itertools.product(l1, l2):
            print e1, e2
    

    prints:

    a c
    a d
    b c
    b d
    a e
    a CB
    b e
    b CB
    a g
    a h
    b g
    b h
    a a
    a j
    a k
    b a
    b j
    b k
    c e
    c CB
    d e
    d CB
    c g
    c h
    d g
    d h
    c a
    c j
    c k
    d a
    d j
    d k
    e g
    e h
    CB g
    CB h
    e a
    e j
    e k
    CB a
    CB j
    CB k
    g a
    g j
    g k
    h a
    h j
    h k
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

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.