查找首字母与Python相关的的英文词汇的小程序

简介: 查找首字母与Python相关的的英文词汇的小程序

查找首字母与Python相关的的英文词汇的小程序
本人是Python学习爱好者,菜鸟。今天偶然看到一篇Python相关的英文词汇资料,然后产生一个想法,利用Python编一个查找的小程序,也算是学以致用吧。

编程思路如下:

  1. 利用首字母(26个英文字母)查找相关的Python英文词汇。比方说以a开头的,有“【‘appearance外表’, ‘assert/assertion异常’, ‘add添加’, ‘args/argument参数’, ‘attribute/attr属性’】”。
  2. 生成一个字典,以首字母为键(首字母小写),以词汇列表为值。
  3. 通过输入的首字母进行查询,然后输出结果。

源码如下:

#_*_coding:utf-8_*_
# 作者      :liuxiaowei
# 创建时间   :3/5/22 8:15 AM
# 文件      :Python常用英语词汇查询.py
# IDE      :PyCharm

'''
编写本程序是受一篇Python英文词汇的文章启发
人生苦短,我用Python
'''
from IPython.display import clear_output
# 创立英文词汇字典
Python_dict = {
   'a':['appearance外表', 'assert/assertion异常', 'add添加', 'args/argument参数', 'attribute/attr属性'],
               'b':['==byte==字节、位组、位元组', 'bool布尔类型', 'bug故障(虫子)', 'break突破/跳出'],
               'c':['cmd/command命令', 'close关闭', 'column列', 'char字符类型', 'class类', 'create创建', 'continue继续', 'case情形',\
                    'capitalize用大写字母或印刷', 'copy复制', 'clear清除', 'coding编码', 'character字符', 'count计数', 'comma引号'],
               'd':['demo演示', 'division除法', 'downloads下载', 'define定义', 'decode解码', 'depth深度', 'default默认', 'dict字典',\
                    'difference差数', 'discord丢弃', 'del/delete删除', 'data数据'],
               'e':['exception异常', 'editor编辑', 'exit退出', 'extends延长,推广,继承', 'encode编码', 'even偶数', 'execute执行',\
                    'expression表达式', 'extend扩展', 'error错误', 'end结果'],
               'f':['finally最后', 'float浮点型', 'factorial阶乘的,因子', 'find查找', 'flush冲刷', 'function方法/函数', 'format格式化',\
                    'file文件'],
               'g':['global全局变量', 'group组'],
               'h':['height高度'],
               'i':['int整型', 'interpret解释', 'interpreter解释器', 'instance实例,情况', 'install安装', 'indentation缩进',\
                    'ignore case或略大小写', 'inside内部', 'info信息', 'infinite无穷', 'import导入', 'item项', 'intersection相交/交叉',\
                    'insert插入', 'input输入', 'invalid无效', 'identifier名称/标识符', 'iterable可迭代对象', 'index索引'],
               'j':[''],
               'k':['kwargs关键字参数', 'key键'],
               'l':['local局部作用域', 'long长整型', '==login==登录', 'list列表', 'lower小写', 'less小于'],
               'm':['main主要的', 'match匹配', 'missing丢失', 'module模块', 'mapping映射', 'max最大', 'min最小'],
               'n':[''],
               'o':['outside外部', 'object对象'],
               'p':['private私有的', 'public公共的/公用的', 'perimeter周长', 'params参数', 'power幂', 'positional位置的', 'prompt提示',\
                    'pop取出/弹出', 'path路径', 'project项目', 'print打印输出'],
               'q':['quit退出', 'quotation引用'],
               'r':['==rename==重命名', 'result结果', 'row行', 'random随机的', 'run运行/跑', 'reset重新设置', 'radius半径', 'regular规则',\
                    'recursion递归', 'required必须', 'range范围', 'remove移除', 'reverse反向', 'replace替换'],
               's':['scripts脚本', 'self自身', 'search查找', 'salary薪水', 'switch判断语句', 'string字符串类型', 'successful成功', 'search查询',\
                    'square平方', 'system系统', 'step步长', 'sep/separate分隔', 'seq/sequence序列', 'swap互换', 'subset子集', 'sub附属',\
                    'superset父集/超集', 'symmetric对称', 'set集合', 'setting设置', 'sort排序', 'strip去除', 'syntax语法', 'start开始'],
               't':['try尝试', 'type类型', 'test测试', 'True真', 'tuple元组', 'title标题'],
               'u':['unexpected不期望的', 'unicode万国码/统一字符标准', 'union联合', 'unsupported不支持的', 'update更新', 'upgrade升级','upper上面'],
               'v':['==variables==变量', 'version版本', 'void空的/没有返回值的', 'value值', 'versus/vs.对抗/相对的'],
               'w':['window窗口', 'width宽度', 'weight重量'],
               'x':[''],
               'y':['yield生产/生成'],
               'z':['zip解压/拉链']}


# # 定义一个函数生成找到的词汇生成器
# def output_word(letter):
#     for word in Python_dict[letter]:
#         # 利用list函数可以生成一个列表
#         yield word

while True:

    try:
        letter = input('Please enter the initial letter of the word you want to find: (a,b,c...z)').lower()
        if  letter in Python_dict.keys():
            clear_output()
            print(f'您要查找的首字母是{letter}相关词汇如下:')
            # 下面的屏蔽语句是配合上面的函数那个思路
            # for word in list(output_word(letter)):
            #     print(word, end='\t')

            for word in Python_dict[letter]:
                if word == '':
                    print('目前没有您查的相关词汇!待系统完善......')
                else:
                    print(word, end='\n')

        else:
            print('No found!')

        question = input('Do you want to quit?(q) or any key to coninute...').lower()
        if question == 'q' or question == 'quit':

            break
        else:
            continue

    except:
        print('请核实输入的内容!')

效果如下:

Please enter the initial letter of the word you want to find: (a,b,c...z)3
No found!
Do you want to quit?(q)
Please enter the initial letter of the word you want to find: (a,b,c...z)z
您要查找的首字母是z相关词汇如下:
zip解压/拉链
Do you want to quit?(q)
Please enter the initial letter of the word you want to find: (a,b,c...z)d
您要查找的首字母是d相关词汇如下:
demo演示
division除法
downloads下载
define定义
decode解码
depth深度
default默认
dict字典
difference差数
discord丢弃
del/delete删除
data数据
Do you want to quit?(q)quit

Process finished with exit code 0

备注
本程序的字典引自博客,感谢博主分享!

总结

此小程序可以修改查找任何相关的命令集,比如Linux,Windows,mac系统等命令。

相关文章
|
1天前
|
小程序 IDE 开发工具
Python编程--个人信息修改小程序
Python编程--个人信息修改小程序
10 2
|
2天前
|
小程序 Linux Python
查找首字母与Python相关的的英文词汇小程序的续篇---进一步功能完善
查找首字母与Python相关的的英文词汇小程序的续篇---进一步功能完善
|
12天前
|
人工智能 小程序 API
文字转语音神器+Python编程搞定语音报时小程序
文字转语音神器+Python编程搞定语音报时小程序
13 2
|
12天前
|
人工智能 小程序 API
ChatTTS+Python编程搞定语音报时小程序
ChatTTS+Python编程搞定语音报时小程序
11 1
|
1天前
|
小程序 IDE 开发工具
Python编写单词复习小程序
Python编写单词复习小程序
|
12天前
|
人工智能 小程序 API
ChatTTS+Python编程实现语音报时小程序
ChatTTS+Python编程实现语音报时小程序
21 0
|
4月前
|
小程序 前端开发 JavaScript
计算机Python项目|django傣族节日及民间故事推广小程序
计算机Python项目|django傣族节日及民间故事推广小程序
|
2月前
|
小程序 前端开发 Java
SpringBoot+uniapp+uview打造H5+小程序+APP入门学习的聊天小项目
JavaDog Chat v1.0.0 是一款基于 SpringBoot、MybatisPlus 和 uniapp 的简易聊天软件,兼容 H5、小程序和 APP,提供丰富的注释和简洁代码,适合初学者。主要功能包括登录注册、消息发送、好友管理及群组交流。
71 0
SpringBoot+uniapp+uview打造H5+小程序+APP入门学习的聊天小项目
|
2月前
|
小程序 前端开发 JavaScript
【项目实战】SpringBoot+uniapp+uview2打造一个企业黑红名单吐槽小程序
【避坑宝】是一款企业黑红名单吐槽小程序,旨在帮助打工人群体辨别企业优劣。该平台采用SpringBoot+MybatisPlus+uniapp+uview2等技术栈构建,具备丰富的注释与简洁的代码结构,非常适合实战练习与学习。通过小程序搜索“避坑宝”即可体验。
67 0
【项目实战】SpringBoot+uniapp+uview2打造一个企业黑红名单吐槽小程序
|
2月前
|
存储 小程序 JavaScript