I´m relatively new to python and I´m using python 3.8 if it matters. I´ve been looking for an answer to how to interpret this. I understand the basics of list comprehension but this nested list comprehension is very challenging to understand for me:
filtred = [str for str in decode.split() if not any(i in str for i in list)]
My interpretation which is wrong is something like this:
list1 = []
filtred=[]
for i in list:
if i in str:
list1.append(True)
else:
list1.append(False)
for str in text.split():
if not any(list1):
filtred.append(str)
I got this from here, where the context is extracting emojis from text:
https://stackoverflow.com/a/50530149/13100800:
EDIT to provide more context
Step 1: Make sure that your text it's decoded on utf-8 text.decode('utf-8')
Step 2: Locate all emoji from your text, you must separate the text character by character [str for str in decode]
Step 3: Saves all emoji in a list [c for c in allchars if c in emoji.UNICODE_EMOJI] full example bellow:
>>> import emoji
>>> text = " me así, bla es se ds "
>>> decode = text.decode('utf-8')
>>> allchars = [str for str in decode]
>>> list = [c for c in allchars if c in emoji.UNICODE_EMOJI]
>>> print list
[u'\U0001f914', u'\U0001f648', u'\U0001f60c', u'\U0001f495', u'\U0001f46d', u'\U0001f459']
if you want to remove from text:
>>> filtred = [str for str in decode.split() if not any(i in str for i in list)]
>>> clean_text = ' '.join(filtred)
>>> print clean_text
me así, bla es se ds
Could someone be kind enough to write the code in the long format?
Thanks in advance