OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Searching for a string from a pre-defined text file before printing ones that don't match

  • Thread starter Thread starter Ethan Ford
  • Start date Start date
E

Ethan Ford

Guest
I'm currently trying to decipher a code using a code breaker that I have to create. I have a list of codes that do not work in the form of a text file and I'm trying to check if the created code is one from the text file, then print the ones that are not.

Code:
        for code in itertools.product(numbers, repeat=n):
            if "0" in code and "4" in code and "5" in code:
                with open('../../OneDrive/Desktop/Codes.txt') as input_file:
                    data = input_file.readlines()
                    for line in data:
                        if code in line:
                            print(''.join(code))

I was hoping that this would work as the code has no errors but it does not. When I remove the text file portion of the code like this:

Code:
        for code in itertools.product(numbers, repeat=n):
            if "0" in code and "4" in code and "5" in code:
               print(''.join(code))

it prints all codes that match the description, however, I want to filter out the ones that match from the text file
<p>I'm currently trying to decipher a code using a code breaker that I have to create. I have a list of codes that do not work in the form of a text file and I'm trying to check if the created code is one from the text file, then print the ones that are not.</p>
<pre><code> for code in itertools.product(numbers, repeat=n):
if "0" in code and "4" in code and "5" in code:
with open('../../OneDrive/Desktop/Codes.txt') as input_file:
data = input_file.readlines()
for line in data:
if code in line:
print(''.join(code))
</code></pre>
<p>I was hoping that this would work as the code has no errors but it does not. When I remove the text file portion of the code like this:</p>
<pre><code> for code in itertools.product(numbers, repeat=n):
if "0" in code and "4" in code and "5" in code:
print(''.join(code))
</code></pre>
<p>it prints all codes that match the description, however, I want to filter out the ones that match from the text file</p>
 
Top