forked from imtiazahmad007/PythonCourse
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassignment_07.py
63 lines (27 loc) · 854 Bytes
/
assignment_07.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Assignment 7
"""
Given 2 strings, a and b, return the number of the positions where
they contain the same length 2 substring. So "xxcaazz" and "xxbaaz"
yields 3, since the "xx", "aa", and "az" substrings appear in the same
place in both strings.
EXAMPLE:
string_match('xxcaazz', 'xxbaaz') → 3
string_match('abc', 'abc') → 2
string_match('abc', 'axc') → 0
"""
#Your Code Below:
# Solution
# def string_match(a, b):
# # Figure which string is shorter.
# shorter = min(len(a), len(b))
# count = 0
#
# # Loop i over every substring starting spot.
# # Use length-1 here, so can use char str[i+1] in the loop
# for i in range(shorter - 1):
# a_sub = a[i:i + 2]
# b_sub = b[i:i + 2]
# if a_sub == b_sub:
# count = count + 1
#
# return count