Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. A B
  2. B C
  3. B D
  4. C E
  5. F G
  6.  
  7. A B C D E
  8. F G
  9.  
  10. import sys
  11.  
  12. res = [] # list of lists
  13. for line in open(sys.argv[1]):
  14. try:
  15. x, y = line.split() # split on space
  16. except ValueError:
  17. line = line.rstrip()
  18. x, y = line.split(',') # retry with comma
  19. for l in res:
  20. if x in l:
  21. if y not in l:
  22. l.append(y)
  23. break
  24. else:
  25. res.append([x, y])
  26.  
  27. for line in res:
  28. print ' '.join(line)
  29.  
  30. large big
  31. big great
  32. great vast
  33. small little
  34. little tiny
  35.  
  36. large big great vast
  37. small little tiny
  38.  
  39. $ awk -f so-162730.awk -F '[[:space:]]+|,' input.txt
  40. A B C D E
  41. F G
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement