[ create a new paste ] login | about

Link: http://codepad.org/ipOvXNwH    [ raw code | output | fork ]

Python, pasted on Nov 11:
import string

def find_substring(needle, haystack):
    index = haystack.find(needle)
    if index == -1:
        return False
    if index != 0 and haystack[index-1] not in string.whitespace:
        return False
    L = index + len(needle)
    if L < len(haystack) and haystack[L] not in string.whitespace:
        return False
    return True

string1 = "ADDLESHAW GODDARD"
string2 = "ADDLESHAW GODDARD LLP"
print find_substring(string1, string2)
print find_substring('a', 'a b')
print find_substring('b', 'a b')


string1 = "ADVANCE"
string2 = "ADVANCED BUSINESS EQUIPMENT LTD"
print find_substring(string1, string2)
print find_substring('a', 'ab')
print find_substring('b', 'ab')


Output:
1
2
3
4
5
6
True
True
True
False
False
False


Create a new paste based on this one


Comments: