polv

export_sort

Dec 21st, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. #! /usr/bin/python3
  2.  
  3. #Number of words in the file
  4. n = 102
  5.  
  6. #Actual coding
  7. def NextLine(filename):
  8.     y = filename.read(1)
  9.     while y != "\n":
  10.         y = filename.read(1)
  11.  
  12. def GoToCol(filename, n):
  13.     x = 0
  14.     while x < n:
  15.         y = filename.read(1)
  16.         while y != delim:
  17.             y = filename.read(1)
  18.         x = x+1
  19.  
  20.         delim = ";"
  21. ssize = 8        
  22. f1 = open("vocabulary.txt", "r")
  23. f2 = open("vocab_sort.txt", "w")
  24.  
  25. while f1.read(1) != "v":
  26.     NextLine(f1)
  27. f1.seek(-1,1)
  28. startpos = f1.tell()
  29.  
  30.  
  31. sort_list = [ f1.read(ssize), ]
  32. sort_order = [ 0, ]
  33. f1.seek(-ssize,1)
  34.  
  35. print(sort_list)
  36. x = 0
  37. while x < n:
  38.     x = x+1
  39.    
  40.     NextLine(f1)
  41.     sort_list2 = [ f1.read(ssize), ]
  42.     sort_order2 = [ x, ]
  43.     f1.seek(-ssize,1)
  44.    
  45.     sort_list = sort_list + sort_list2
  46.     sort_order = sort_order + sort_order2
  47.    
  48. print(sort_list)
  49. print(sort_order2)
  50.  
  51. x = 0
  52. while x < n:
  53.     indexmin = x
  54.     y = x
  55.     while y < n:
  56.         if sort_list[indexmin] > sort_list[y]:
  57.             indexmin = y
  58.         y = y+1
  59.     temp = sort_list[x]
  60.     sort_list[x] = sort_list[indexmin]
  61.     sort_list[indexmin] = temp
  62.    
  63.     temp = sort_order[x]
  64.     sort_order[x] = sort_order[indexmin]
  65.     sort_order[indexmin] = temp
  66.    
  67.     x = x+1
  68.  
  69. print(sort_list)
  70. print(sort_order)
  71.  
  72. x = 0
  73. while x < n:
  74.     f1.seek(startpos,0)
  75.    
  76.     y = 0
  77.     while y < sort_order[x]:
  78.         NextLine(f1)
  79.         y = y+1
  80.    
  81.     z = f1.read(1)
  82.     while z != "\n":
  83.         f2.write(z)
  84.         z = f1.read(1)
  85.    
  86.     f2.write("\n")
  87.     x = x+1
  88.    
  89. f1.close()
  90. f2.close()
Advertisement
Add Comment
Please, Sign In to add comment