SoFunction
Updated on 2024-11-12

How to make an English dictionary in python

In this article, the example shares the specific code for python to make English dictionary for your reference, the details are as follows

Functions are adding words, adding word meanings multiple times, querying, quitting, and creating word files.

keys=[]
dic={}
def rdic():
  fr = open('','r')  
  for line in fr:
    line = ("\n",'')
    v = (':')
    dic[v[0]] = v[1]
    (v[0])
  ()
def centre():
  n = input("Please enter to access the appropriate module (add, query, exit):")
  if n == "Add":
    key= input("plsease input English:")
    if key not in keys:
      value=input("please input Chinese:")
      dic[key]=value
      (key)
    else :
      t=input("Enter Y if adding a new meaning, otherwise enter N:")
      if ( t=='Y'):
        temp=""
        temp=temp+dic[key]
        key1= input("Please enter Chinese.")
        temp=temp+","+key1
        print(temp)
        #(temp)
        dic[key]=temp
        print(dic)
        return 0
      else:
        return 0
  elif n== "Query":
    key= input("plsease input English:")
    print(keys)
    print(dic)
    if key not in keys:
      print("the english not in the dic.")
    else :
      print(dic[key])
  elif n == "Exit." :
    return 1
  else :
    print("Input error.")
    return 0
def wdic():
  #print("!")
  with open('','w') as fw:
    for k in keys:
      (k+':'+dic[k]+'\n')
def main():
  rdic()
  while True:
    print(keys)
    print(dic)
    n=centre()
    print(keys)
    print(dic)
    if n==1:
      break
    if n==0:
      continue
  wdic()
main()

This is the whole content of this article.