Advertisement
Guest User

Untitled

a guest
Jul 1st, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. user_names = []
  4. with open(filename) as f: # change the filename to "yourfile.txt"
  5.     for l in f:
  6.         if "@" in l:
  7.             # it seems we can assume every line we're interested in tags a user
  8.             pieces = l.split()
  9.             user_names.append(pieces[0]) # first word on the line is a username
  10.             user_names.extend([p for p in pieces[1:] if p[0] == '@']) # find everything else that starts with @
  11.  
  12. updated_user_names = [u if u[0] == '@' else '@' + u for u in user_names]
  13.  
  14. with open("output.txt", "w") as f:
  15.     for u in set(updated_user_names):
  16.         f.write(u + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement