4 examples of '2d string array substring search in python' in Python

Every line of '2d string array substring search in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
60def test(self):
61 self.assertEqual(string_rotation("hoolahoop", "lahoophoo"), True)
62 self.assertEqual(string_rotation("waterbottle", "erbottlewat"), True)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

62def main():
63 s = Solution()
64 print s.findSubstring("barfoothefoobarman", ["bar", "foo"])
65 print s.findSubstring("barfoofoobarthefoobarman", ["bar","foo","the"])
66 print s.findSubstring("wordgoodgoodgoodbestword", ["word","good","best","good"])
67 print s.findSubstring("aaa", ["aa","aa"])
68 print s.findSubstring("aaaaaa", ["aaa","aaa"])
2def strStr(self, haystack, needle):
3 """
4 :type haystack: str
5 :type needle: str
6 :rtype: int
7 """
8 if len(haystack) == len(needle):
9 if haystack == needle:
10 return 0
11 else:
12 return -1
13
14 for i in range(0, len(haystack)):
15 k = i
16 j = 0
17 while j < len(needle) and k < len(haystack) and haystack[k] == needle[j]:
18 j += 1
19 k += 1
20 if j == len(needle):
21 return i
22 return -1 if needle else 0
43def _fuzzy_search(self, string, position=0, array=None):
44 """
45 Approximate text search
46 """
47 if not array:
48 array = self.array
49
50 if len(array) == 0:
51 return array
52 elif len(array) == 1:
53 if difflib.SequenceMatcher(a=string,
54 b=array[0][:len(string)]).ratio() < 0.70:
55 return []
56 else:
57 return array
58 else:
59 start_point = array[0]
60 end_point = array[-1]
61 if len(start_point) > position and len(end_point) > position and \
62 start_point[position] == end_point[position]:
63 return self._fuzzy_search(string, position + 1, array)
64 else:
65 length = len(array) / 2
66 left = self._fuzzy_search(string, position, array[:length])
67 right = self._fuzzy_search(string, position, array[length:])
68 return left + right

Related snippets