pattern-matching

How can I tell if a string repeats itself in Python?

How can I tell if a string repeats itself in Python? Question: I’m looking for a way to test whether or not a given string repeats itself for the entire string or not. Examples: [ ‘0045662100456621004566210045662100456621’, # ‘00456621’ ‘0072992700729927007299270072992700729927’, # ‘00729927’ ‘001443001443001443001443001443001443001443’, # ‘001443’ ‘037037037037037037037037037037037037037037037’, # ‘037’ ‘047619047619047619047619047619047619047619’, # ‘047619’ ‘002457002457002457002457002457002457002457’, # ‘002457’ ‘001221001221001221001221001221001221001221’, # …

Total answers: 14

pandas: Rolling correlation with fixed patch for pattern-matching

pandas: Rolling correlation with fixed patch for pattern-matching Question: Happy New Year. I am looking for a way to compute the correlation of a rolling window and a fixed window (‘patch’) with pandas. The ultimate objective is to do pattern matching. From what I read on the docs, AND HOPEFULLY I MISSED SOMETHING, corr() or …

Total answers: 2

Python regex string matching?

Python regex string matching? Question: I’m having a hell of a time trying to transfer my experience with javascript regex to Python. I’m just trying to get this to work: print(re.match(‘e’,’test’)) …but it prints None. If I do: print(re.match(‘e’,’est’)) It matches… does it by default match the beginning of the string? When it does match, …

Total answers: 2

RegExp match repeated characters

RegExp match repeated characters Question: For example I have string: aacbbbqq As the result I want to have following matches: (aa, c, bbb, qq) I know that I can write something like this: ([a]+)|([b]+)|([c]+)|… But I think i’s ugly and looking for better solution. I’m looking for regular expression solution, not self-written finite-state machines. Asked …

Total answers: 6

Search for string allowing for one mismatch in any location of the string

Search for string allowing for one mismatch in any location of the string Question: I am working with DNA sequences of length 25 (see examples below). I have a list of 230,000 and need to look for each sequence in the entire genome (toxoplasma gondii parasite). I am not sure how large the genome is, …

Total answers: 14

Pattern matching of lists in Python

Pattern matching of lists in Python Question: I want to do some pattern matching on lists in Python. For example, in Haskell, I can do something like the following: fun (head : rest) = … So when I pass in a list, head will be the first element, and rest will be the trailing elements. …

Total answers: 10