Advertisement
Guest User

sort wiki data

a guest
Mar 19th, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import re
  2.  
  3. infos = []
  4. with open("data.txt", encoding="utf8") as f:
  5. temp_data = ""
  6. temp_number = 10000000000
  7. line_count = 0
  8. for line in f:
  9. #print(line, end="")
  10. if line.startswith("|-"):
  11. infos.append((temp_data, temp_number))
  12. #print(temp_data, temp_number)
  13. #input()
  14. temp_data = ""
  15. temp_number = 10000000000
  16. line_count = 0
  17. temp_data += line
  18. if line_count == 2:
  19. line = re.sub("(<!--.*?-->)", "", line)
  20. temp_number = int(re.sub('[^0-9]','', line))
  21. #print(temp_number)
  22. #input()
  23. line_count += 1
  24.  
  25. infos.sort(key=lambda x: -x[1])
  26. with open("data_sorted.txt", mode="w", encoding="utf8") as f:
  27. f.write(''.join(x[0] for x in infos))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement