Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the any() method not return what I think it should?

Tags:

python

I'm trying to set up a bot that deletes messages if they include a specific string from a list anywhere in their body.

This code works exactly how I think it should: (returns True)

s = 'test upvote test'
upvote_strings = ['upvote', 'up vote', 'doot']
print(any(x in s for x in upvote_strings))

But this does not: (returns False)

s = 'your upvotе bot thing works fine lmao'
upvote_strings = ['upvote', 'up vote', 'doot']
print(any(x in s for x in upvote_strings))
like image 613
Jacob Avatar asked Apr 09 '19 22:04

Jacob


People also ask

What does it mean if a method does not return a value?

If a method does not return a value, it must be declared to return void . However, the pop() method in the Stack class returns a reference data type: an object. Methods use the return operator to return a value. Any method that is not declared void must contain a return statement.

Can a method not return anything?

A method does not have to return something, but all methods need to have a return type. The return type tells Java what type of value it can expect the method to return, the void type is just there to tell Java that the method does in fact not return anything.

Why return is not working in Java?

Java is protecting you from having possible executions that would miss the return statement entirely. e.g. print(0, 5, fillcharac); In this case, the outer loop would never execute and the method would immediately exit, but Java would have no idea what the method should return.

Can a function not return anything Python?

In Python, it is possible to compose a function without a return statement. Functions like this are called void, and they return None, Python's special object for "nothing".


1 Answers

One of those e is not ASCII:

>>> import unicodedata
>>> unicodedata.name(s[10])
'CYRILLIC SMALL LETTER IE'
>>> unicodedata.name(upvote_strings[0][-1])
'LATIN SMALL LETTER E'

unidecode can help:

>>> e1 = s[10] 
>>> e2 = upvote_strings[0][-1] 
>>> e1 == e2 
False
>>> from unidecode import unidecode
>>> unidecode(e1) == "e" == unidecode(e2)
True
like image 147
wim Avatar answered Oct 20 '22 01:10

wim