[python] WorkingPython

Viewer

copydownloadembedprintName: WorkingPython
  1. import json
  2.  
  3. = open('/home/heyhey/progs/JS/countries.json')
  4.    
  5. data = json.load(f)
  6.  
  7. keys=['cym','deu','fra','hrv','ita','jpn','nld','por','rus','spa']
  8.  
  9. key = input('Enter the key:')
  10.  
  11. def translate(key):
  12.     if key not in keys:
  13.         print('Key is not supported!')
  14.     elif key is None:
  15.         print('Parameter cannot be empty!')
  16.     else:
  17.         for i in range(len(data)):
  18.           print(data[i]['translations'][key])
  19.     
  20.     
  21. translate(key)
  22.  
  23.  
  24. f.close()

Editor

You can edit this paste and save as new:


File Description
  • WorkingPython
  • Paste Code
  • 24 Mar-2022
  • 485 Bytes
You can Share it: