sous_chaine.py
1 |
def recherche(sous_chaine, chaine): |
---|---|
2 |
|
3 |
for position in range(len(chaine)): |
4 |
|
5 |
if position + len(sous_chaine) <= len(chaine): |
6 |
if chaine[position] == sous_chaine[0]: |
7 |
sous_chaine_possible = True
|
8 |
position_sous_chaine = 0
|
9 |
|
10 |
while sous_chaine_possible and position_sous_chaine < len(sous_chaine): |
11 |
if chaine[position + position_sous_chaine] == sous_chaine[position_sous_chaine]:
|
12 |
position_sous_chaine += 1
|
13 |
else:
|
14 |
sous_chaine_possible = False
|
15 |
|
16 |
if sous_chaine_possible:
|
17 |
return True |
18 |
return False |
19 |
|
20 |
|
21 |
print(recherche("ut", "actuel")) |
22 |
print(recherche("tu", "actuel")) |