Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving duplicates and preserving order when elements inside the list is list itself
    primarykey
    data
    text
    <p>I have a following problem while trying to do some nodal analysis:</p> <p>For example:</p> <pre><code>my_list=[[1,2,3,1],[2,3,1,2],[3,2,1,3]] </code></pre> <p>I want to write a function that treats the element_list inside my_list in a following way:</p> <blockquote> <p>-The number of occurrence of certain element inside the list of my_list is not important and, as long as the unique elements inside the list are same, they are identical.</p> <p>Find the identical loop based on the above premises and only keep the first one and ignore other identical lists of my_list while preserving the order.</p> </blockquote> <p>Thus, in above example the function should return just the first list which is [1,2,3,1] because all the lists inside my_list are equal based on above premises.</p> <p>I wrote a function in python to do this but I think it can be shortened and I am not sure if this is an efficient way to do it. Here is my code:</p> <pre><code>def _remove_duplicate_loops(duplicate_loop): loops=[] for i in range(len(duplicate_loop)): unique_el_list=[] for j in range(len(duplicate_loop[i])): if (duplicate_loop[i][j] not in unique_el_list): unique_el_list.append(duplicate_loop[i][j]) loops.append(unique_el_list[:]) loops_set=[set(x) for x in loops] unique_loop_dict={} for k in range(len(loops_set)): if (loops_set[k] not in list(unique_loop_dict.values())): unique_loop_dict[k]=loops_set[k] unique_loop_pos=list(unique_loop_dict.keys()) unique_loops=[] for l in range(len(unique_loop_pos)): unique_loops.append(duplicate_loop[l]) return unique_loops </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload