title: Searching through index number in a .txt file (JSON format) in Python code
body: <p>I am a newbie to python and having some difficulties in programming. I have to search through the index number in a data.txt file and then delete the whole item according to the input of the user. My code is as follows:</p>
  
  <pre><code>    if option == 'd':
          if 'name' in open('data.txt').read():
              ind = int (input ("Menu item number to delete: "))
              with open ('data.txt') as data_file:
                  data = json.load(data_file)
              if ind in data[ind]:
                  del data[ind]
                  json.dump(data, open('data.txt', 'w'))
                  data_file.close()
                  print ('Menu item deleted.\n')
              else:
                  print ('No such items exist')
                  main()
              main()
          else:
              print ('There are no menu items saved')
              main()
  </code></pre>
  
  <p>For e.g. if the user enters the 3, the 3rd item will be deleted. The code is working fine but I also have to find that whether the user entered index exists in the file or not and I am having errors in that through the command if ind in data[ind]: The error is shown below:</p>
  
  <p>File "D:/R/043/N.py", line 41, in inputSomething
      if ind in data[ind]:
  IndexError: list index out of range</p>
  
  <p>Immediate help will be appreciated.</p>