Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- user_names = []
- with open(filename) as f: # change the filename to "yourfile.txt"
- for l in f:
- if "@" in l:
- # it seems we can assume every line we're interested in tags a user
- pieces = l.split()
- user_names.append(pieces[0]) # first word on the line is a username
- user_names.extend([p for p in pieces[1:] if p[0] == '@']) # find everything else that starts with @
- updated_user_names = [u if u[0] == '@' else '@' + u for u in user_names]
- with open("output.txt", "w") as f:
- for u in set(updated_user_names):
- f.write(u + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement