Skip to content

Commit

Permalink
Extend answer to Exercise 1-31
Browse files Browse the repository at this point in the history
  • Loading branch information
schedutron committed May 17, 2017
1 parent 113a61b commit 7110bd9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions 1-31answer.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
We can use the following 'filter':

removedHash = re.sub(r'#\S+', '', tweet)
scrubbedTweet = re.sub(r'^RT( @[^\s@]+)+|^\.+', '', removedHash).lstrip()
def filter(tweet, meta=False):
findHash = re.findall(r'#\S+', tweet)
elements = {}
if findHash and meta:
elements['hashtags'] = hashtag.lstrip('@') for hashtag in findHash
findRT = re.search(r'^RT(?: @[^\s@]+)+', removedHash)
if findRT and meta:
users = findRT.group().split()
users.remove('RT')
elements['RT'] = tuple(users)
scrubbedTweet = re.sub(r'(^RT( @[^\s@]+)+|^\.+)|#\S+', '', tweet).lstrip()
if meta:
return (scrubbedTweet, elements)
return scrubbedTweet

0 comments on commit 7110bd9

Please sign in to comment.