Note that there are some explanatory texts on larger screens.

plurals
  1. POPython match all substrings and reversed strings
    primarykey
    data
    text
    <p>I have to match all occurrences of substring in a string and return all match starting positions:</p> <p>example of input data:</p> <pre><code>2 4 AC TGGT 4 25 CATA TCATATGCAAATAGCTGCATACCGA 0 0 ## to end the file </code></pre> <p>I would like to do this without using numbers in such lines as it seems not really necessary;(but they will still be in the input files) </p> <p>And I don't know exactly what's wrong with this code, but it keeps printing (infinity loop) of printing 0s on the output file. </p> <pre><code>#!/usr/bin/env python import sys from operator import itemgetter def find_all(a_str, sub): start = 0 while True: start = a_str.find(sub, start) if start == -1: return yield start start += len(sub) if __name__ == '__main__': testnum=0 input_file = open(sys.argv[1]) #input_lines=input_file.split("\n") output_file = open(sys.argv[2],"w") while True: testnum+=1 values_raw = input_file.readline() #values_raw=raw_input() ##rubish values=values_raw.split() flag=0 for element in values: if element == "0": break string1=str(input_file.readline()) string2=str(input_file.readline()) lista = find_all(string2,string1) output_file.write("\nTeste "+str(testnum)+"\nocorrencia direta: ") for item in lista: output_file.write(str(item)+" ") #reversed search string1=string1[::-1] lista = find_all(string2,string1) output_file.write("\nTeste "+str(testnum)+"\nocorrencia inversa complementar: ") for item in lista: output_file.write(str(item)+" ") if ((len(string1)==0)): break </code></pre> <p>I accidentally removed the string1 and string2 lines when pasting the code //I match for the original and for the reversed match, but as the code is almost the same I thought I shouldn't post it too. </p>
    singulars
    1. This table or related slice is empty.
    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.
    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