-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathessfunction.py
More file actions
58 lines (50 loc) · 1.34 KB
/
essfunction.py
File metadata and controls
58 lines (50 loc) · 1.34 KB
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
A='hello sir bestest lucky'
R='hello sir best lucky'
M='jaguar is a beautiful car'
#comparaison des mots: check if ch fits in sh
def compare(ch,sh):
e=ch[0]
for i in range(len(sh)):
if sh[i]==ch[0]:
k=i
l=1
for j in range(1,len(ch)):
k+=1
if sh[k]!=ch[j]:
break;
l+=1
if l==len(ch):
return True
return False
#search for ch1 (characters) in ch2 (charcters)
def exist(ch1,ch2):
searchin=ch2.split()
searchfor=ch1.split()
e=0
for i in range(len(searchfor)):
for j in range(len(searchin)):
if searchfor[i]==searchin[j]:
e+=1
if e!=0:return True
else: return False
#if ch charcter matches one of the charcters on list L
def match(ch,L):
for i in range(len(L)):
if exist(ch,L[i]):
return True
return False
#match a sentence on a list L:
def matchG(sentence,L):
sp=sentence.split()
for i in range(len(sp)):
if match(sp[i],L):
return True
return False
#count match
def countmatch(sentence,L):
sp=sentence.split()
e=0
for i in range(len(sp)):
if match(sp[i],L):
e+=1
return e