fork download
  1. #!/usr/bin/python3
  2. import os
  3.  
  4. def find_pair(n, pos):
  5. n_keys = list(n.keys())
  6.  
  7. with open("output{}.txt".format(pos), "w") as fout:
  8. fout.truncate()
  9. while n_keys:
  10. lead = n_keys.pop(0)
  11. group = [lead]
  12.  
  13. for i in range(10):
  14. s = lead[:pos] + str(i) + lead[pos+1:];
  15. if s in n_keys:
  16. group.append(s)
  17. n_keys.remove(s)
  18.  
  19. if len(group)>1:
  20. for i in group:
  21. print("{} ==> {}".format(i, n[i][9]), file=fout)
  22. print(file=fout)
  23.  
  24. if __name__ == '__main__':
  25. with open("charno.txt", "r") as fin:
  26. text = fin.read()
  27.  
  28. x = text.split()
  29.  
  30. n = {}
  31. for i in x:
  32. index = i[0:9]
  33. n[index] = i
  34.  
  35. for i in range(0, 9):
  36. find_pair(n, i)
  37.  
  38. # End of differential.py
Runtime error #stdin #stdout #stderr 0.14s 23356KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 25, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'charno.txt'