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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:58:00+00:00 2026-06-10T02:58:00+00:00

Context – developing algorithm to determine loop flows in a power flow network. Issue:

  • 0

Context – developing algorithm to determine loop flows in a power flow network.

Issue:

I have a list of lists, each list represents a loop within the network determined via my algorithm. Unfortunately, the algorithm will also pick up the reversed duplicates.

i.e.

L1 = [a, b, c, -d, -a]

L2  = [a, d, c, -b, -a]

(Please note that c should not be negative, it is correct as written due to the structure of the network and defined flows)

Now these two loops are equivalent, simply following the reverse structure throughout the network.

I wish to retain L1, whilst discarding L2 from the list of lists.
Thus if I have a list of 6 loops, of which 3 are reversed duplicates I wish to retain all three.

Additionally, The loop does not have to follow the format specified above. It can be shorter, longer, and the sign structure (e.g. pos pos pos neg neg) will not occur in all instances.

I have been attempting to sort this by reversing the list and comparing the absolute values.

I am completely stumped and any assistance would be appreciated.

Based upon some of the code provided by mgibson I was able to create the following.

def Check_Dup(Loops):
    Act = []
    while Loops:
        L = Loops.pop()
        Act.append(L)
        Loops = Popper(Loops, L)
    return Act

def Popper(Loops, L):
    for loop in Loops:
        Rev = loop[::-1]
        if all (abs(x) == abs(y) for x, y in zip(loop_check, Rev)):
            Loops.remove(loop)
    return Loops

This code should run until there are no loops left discarding the duplicates each time. I’m accepting mgibsons answers as it provided the necessary keys to create the solution

  • 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-06-10T02:58:02+00:00Added an answer on June 10, 2026 at 2:58 am

    I’m not sure I get your question, but reversing a list is easy:

    a = [1,2]
    a_rev = a[::-1]  #new list -- if you just want an iterator, reversed(a) also works.
    

    To compare the absolute values of a and a_rev:

    all( abs(x) == abs(y) for x,y in zip(a,a_rev) )
    

    which can be simplified to:

    all( abs(x) == abs(y) for x,y in zip(a,reversed(a)) )
    

    Now, in order to make this as efficient as possible, I would first sort the arrays based on the absolute value:

    your_list_of_lists.sort(key = lambda x : map(abs,x) )
    

    Now you know that if two lists are going to be equal, they have to be adjacent in the list and you can just pull that out using enumerate:

    def cmp_list(x,y):
        return True if x == y else all( abs(a) == abs(b) for a,b in zip(a,b) )
    
    duplicate_idx = [ idx for idx,val in enumerate(your_list_of_lists[1:]) 
                      if cmp_list(val,your_list_of_lists[idx])  ]
    
    #now remove duplicates:
    for idx in reversed(duplicate_idx):
        _ = your_list_of_lists.pop(idx)
    

    If your (sub) lists are either strictly increasing or strictly decreasing, this becomes MUCH simpler.

    lists = list(set( tuple(sorted(x)) for x in your_list_of_lists ) ) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Context: I have a Query that returns a list of availables[choices]. I have an
Context I have this function which synchronize a list of sites between a table
Context I have this piece of Java Code btn.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent
Context I have a tree view with folders and files: Additional info All files
Context I have a tree view with folders ( .directory ): When I mouseover
Context: I have a clojure-based crossword app whose main ui is a JTabbedPane with
Context When iterating over a set of Rdata files (each containing a character vector
Context I have a very large number of small classes or structures . The
Context I have 2 different versions of an assembly installed in GAC, version 1.0
Context I'm developing an application in Java. I want a fairly high resolution map/globe

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.