0

hello i tried to make a email parser but it behaves weirdly can someone tell me why

def parser(wrds):
    s = set()
    for wrd in wrds:
        splited_wrd = wrd.split(' ')
        for i in range(len(splited_wrd)):
            wrds_indexed = splited_wrd[i]
            if ('@' and '.' in wrds_indexed) and (len(wrds_indexed) > 13):
                s.add(wrds_indexed)
    yield from s


x = 'heykidhello@gmail.com', 'heykidgmail.com', 'heykidhello@gmailcom','h@gmail.com'
print(list(parser(x)))

output:

['heykidgmail.com', 'heykidhello@gmail.com']                                                                                                                                            
>>> 

can someone tell me why does heykidgmail.com is in the list when it clearly doesnt have '@'

>>> '@' and '.' in 'heykidgmail.com'                                                                                                                                                    
True

when i ran it in console why does it say True when @ is not in the word ?

Jishnu
  • 106
  • 9

1 Answers1

3
'@' and '.' in 'heykidgmail.com'

does not do what you think it does.

It is interpreted as

bool('@')  and  bool('.' in 'heykidgmail.com')

Or

True  and  bool('.' in 'heykidgmail.com')

Thus

bool('.' in 'heykidgmail.com')

You need to test both independently:

s = 'heykidgmail.com'
'@' in s and '.' in s
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328