How to find permutations in a list then remove them?
<p>I'm trying to find a permutation of another number in this txt file and then add them to a list:</p>

<pre><code>167
168
148
143
289
194 
683
491
</code></pre>

<p>In this file, the permutations are 491 and 194.</p>

<p>This is my code:</p>

<pre><code>numberList = []

file = open("file.txt", "r")
for line in file:
    numberList.append(line)
</code></pre>

<p>Now they're added to <code>numberList</code>, how do I remove them (491 and 194) from this list.</p>

<p>So, you can do this in just 3 additional lines of code:</p>

<ol>
<li>Sort each item in the list so that permutations will match</li>
<li>Check each item on the list to see where there are permutations, and create a list of those indices</li>
<li>Create the new list do not add the indices that were identified as permutations:</li>
</ol>

<p>So the whole program will look like this:</p>

<pre><code>numberList = []

file = open("file.txt", "r")
for line in file:
    numberList.append(line.strip())

x = [sorted(y) for y in numberList]
indices = [i for i, item in enumerate(x) if x.count(item) &gt; 1]
numberList = [item for i, item in enumerate(numberList) if i not in indices]
</code></pre>

<p>Results:</p>

<pre><code>&gt;&gt;&gt; numberList
[167, 168, 148, 143, 289, 683]
&gt;&gt;&gt; 
</code></pre>

python permutation