Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> "Ada Lovelace".find(" ") 3 >>> "Alan Turing".find("n",4) 9
def myfirst_yoursecond(p,q): pindex = p.find(" ") qindex = q.find(" ") return p[ :pindex] == q[qindex+1:]
>>> "Python is fun".split() ['Python', 'is', 'fun'] >>> "July-August 1842".split() ['July-August', '1842'] >>> "6*9==42".split() ['6*9==42']
Regular expression [1-3][4-8][a-b]
>>> r"[0-9][0-9]" >>> re.findall(r"[0-9][0-9]", "July 28, 1821") >>> re.findall(r"[0-9][0-9]", "12345")
r”a+”, r”[0-1]+”
regular expression rule is maximum match eat single match
re.findall(r”[0-9][ ][0-9]+”, “a1 2b cc3 44d”)
r”[0-9]+%”
r”[a-z]+|[0-9]+”,”Goothe 1798″
regexp = r”[a-z]+-?[a-z]+”
>>> re.findall(r”[0-9].[0-9]”, “1a1 222 cc3”)
[‘1a1’, ‘222’]
edges = {(1,'a'):2, (2, 'a'): 2, (2, '1'): 3, (3, '1'): 3}