-1

I receiving a stream of tweets.

I want to check each tweet and if the tweet contains the word hello I don't want to do anything but if it does not include hello I want to print it.

Can't seem to get my code working though.

if "hello" not in data['text'].encode('utf-8'):
        print data['text'].encode('utf-8')
Sami
  • 1,374
  • 1
  • 16
  • 43
  • assuming `data['text'].encode('utf-8')` is a string. then i think you want `if "hello" in data['text'].encode('utf-8'):` instead of `not in`. the way you have it, its going to print everything that DOESNT have hello in it – TehTris Feb 16 '15 at 16:02
  • Yes I need to exclude tweets with the word hello in it, I think the issue is that data['text'].encode('utf-8') may not be a python or comparable string? – Sami Feb 16 '15 at 16:05
  • run `print type(data['text'].encode('utf-8'))` to find that out. are you in python3 or 2? – TehTris Feb 16 '15 at 16:07
  • Yes checked it, it returns str and running 2.7.5. – Sami Feb 16 '15 at 16:53

1 Answers1

0

Got it working the issue was I was checking if the string was included however not taking into consideration the case of the strings, got it working using lower() and comparing both strings in lowercase.

Sami
  • 1,374
  • 1
  • 16
  • 43