Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import csv
  2.  
  3. def isEmpty(lst):
  4. for i in lst:
  5. if i:
  6. return False
  7. return True
  8.  
  9. def removeEmpty(tbl):
  10. for i in tbl:
  11. if isEmpty(i):
  12. tbl.remove(i)
  13. return tbl
  14.  
  15. def splitAndSort(column):
  16. column_tmp = []
  17. for i in column:
  18. i = i.replace("+", " ").split(" ")
  19. i.sort()
  20. if i.count(''):
  21. i.remove('')
  22. if not column_tmp.count(i):
  23. column_tmp.append(i)
  24. return column_tmp
  25.  
  26. def removeFromCol2(col1, col2):
  27. for i in col1:
  28. if col2.count(i):
  29. col2.remove(i)
  30. return col2
  31.  
  32. table = []
  33.  
  34. for i in csv.reader(open("/home/alexander/test/python/input.csv")):
  35. if not isEmpty(i):
  36. table.append(i)
  37.  
  38. print table
  39. table = removeEmpty(zip(*table))
  40. print table
  41. table = [splitAndSort(i) for i in table]
  42. print table
  43.  
  44. result = [table[0]]
  45. for i in range(0, len(table)-1):
  46. result.append(removeFromCol2(table[i], table[i+1]))
  47.  
  48. print result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement