📜  Python 中的简单字典 - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:19.980000             🧑  作者: Mango

代码示例1
import string

# Edited by Sadman Sakib

dic = {'greet': 'something that you say or do to greet somebody',
       'sleep': ' [intransitive] to rest with your eyes closed and your mind and body not active',
       'morning': 'The early part of the day from the time when people wake up until 12 o\'clock in the middle of the '
                  'day or before lunch',
       'noon': '12 o’clock in the middle of the day',
       'night': 'the time between one day and the next when it is dark, when people usually sleep',
       'evening': '[countable, uncountable] the part of the day between the afternoon and the time you go to bed'}

words = []  # for printing a welcome message
dic_keys = list(dic.keys())
for i in dic_keys:  # displaying upper case of lowercase words
    x = i.upper()
    words.append(x)  # appending in words variable

print('Welcome to Dictionary!\n'
      'Here is a list of variable words which you can search', words)

user_input = input('Enter a word for search: ')
dic_search = user_input.lower()  # converting into lowercase

output = dic[dic_search]  # searching on dic

print(user_input, 'means: ', output)