As the title says I tried to make it as an anti-spam measure A function that returns True if it has the specified number of characters Forgive spaghetti source code You may not be able to use it so much w After powering up, edit to make a new one
Take out character by character and add it to the one to compare it and check if it exists
def similer(b,a,m):
al = list(a)
cc = ""
cu = 0
co = 0
cuo = 0
for c in al:
co += 1
for ck in al:
cuo += 1
if cuo-1 < co-1:
continue
cc = cc + ck
cu += 1
if cu == m:
break
if cu == m:
if cc in b:
return True
cc = ""
cuo = 0
cu = 0
return False
#Spaghetti source code w
#Maybe it can be made more compact, but please forgive me
#It was a hassle
This one is overwhelmingly easy to understand and compact I learned something Thank you
def similer(b,a,m):
return any(a[i:i+m] in b for i in range(len(a) - m))
#Take it with a slice and confirm it and return with any
#It will be a great study
similer (characters to be checked, characters to be checked, length of words to check if they are worn)
Can be used in.
A spam message that sends a message with random characters that was a chat.
True
is back.
b = """Hello. This is Flage Chat
嘮"""
a = """Hello. This is Flage Chat
蕻"""
print(similer(b,a,5))
# True
False is back because it's not spam.
b = """i-FILTER false positive w"""
a = """Was put in a long time ago"""
print(similer(b,a,5))
# False
Note! When using it in a chat app, check it several times or repeatedly. If you send it with a person's name, it will be misjudged as spam. Sometimes short sentences cannot be detected. Let's repeat it by increasing the last argument of the function in order.
If you compare these things, the name of the person tasuren will be True.
b = """Did tasuren do it?"""
a = """Because tassuren did hugahuga"""
print(similer(b,a,5))
# True
So
When True
is returned as spam five times in a row when sending a message five times
It's spam! It is better to make it feel like letting you know.
It's the end!
Recommended Posts