Python学习之路-字典外传

__author__ = "KuanKuan"
info = {‘teacher1‘: ‘苍井空‘,
      ‘teacher2‘: ‘京香‘,
      ‘teacher3‘: ‘波多野结衣‘,
      ‘teacher4‘: ‘小泽玛利亚‘,
      ‘teacher5‘: ‘上原瑞惠‘,
      ‘teacher6‘: ‘樱井莉亚‘,
      ‘teacher7‘: ‘桃谷绘里香‘}
print(info.keys())
d = list(info.keys())[0]
b = list(info.values())[0]
print(d,b)

for index in range(len(info)):
    print(index,list(info.keys())[index],list(info.values())[index])
print("~"*168)
for index in range(len(info)):
    print(index,list(info.keys()),list(info.values()))
# dict_keys([‘teacher1‘, ‘teacher2‘, ‘teacher3‘, ‘teacher4‘, ‘teacher5‘, ‘teacher6‘, ‘teacher7‘])
# teacher1 苍井空
# 0 teacher1 苍井空
# 1 teacher2 京香
# 2 teacher3 波多野结衣
# 3 teacher4 小泽玛利亚
# 4 teacher5 上原瑞惠
# 5 teacher6 樱井莉亚
# 6 teacher7 桃谷绘里香
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 0 [‘teacher1‘, ‘teacher2‘, ‘teacher3‘, ‘teacher4‘, ‘teacher5‘, ‘teacher6‘, ‘teacher7‘] [‘苍井空‘, ‘京香‘, ‘波多野结衣‘, ‘小泽玛利亚‘, ‘上原瑞惠‘, ‘樱井莉亚‘, ‘桃谷绘里香‘]
# 1 [‘teacher1‘, ‘teacher2‘, ‘teacher3‘, ‘teacher4‘, ‘teacher5‘, ‘teacher6‘, ‘teacher7‘] [‘苍井空‘, ‘京香‘, ‘波多野结衣‘, ‘小泽玛利亚‘, ‘上原瑞惠‘, ‘樱井莉亚‘, ‘桃谷绘里香‘]
# 2 [‘teacher1‘, ‘teacher2‘, ‘teacher3‘, ‘teacher4‘, ‘teacher5‘, ‘teacher6‘, ‘teacher7‘] [‘苍井空‘, ‘京香‘, ‘波多野结衣‘, ‘小泽玛利亚‘, ‘上原瑞惠‘, ‘樱井莉亚‘, ‘桃谷绘里香‘]
# 3 [‘teacher1‘, ‘teacher2‘, ‘teacher3‘, ‘teacher4‘, ‘teacher5‘, ‘teacher6‘, ‘teacher7‘] [‘苍井空‘, ‘京香‘, ‘波多野结衣‘, ‘小泽玛利亚‘, ‘上原瑞惠‘, ‘樱井莉亚‘, ‘桃谷绘里香‘]
# 4 [‘teacher1‘, ‘teacher2‘, ‘teacher3‘, ‘teacher4‘, ‘teacher5‘, ‘teacher6‘, ‘teacher7‘] [‘苍井空‘, ‘京香‘, ‘波多野结衣‘, ‘小泽玛利亚‘, ‘上原瑞惠‘, ‘樱井莉亚‘, ‘桃谷绘里香‘]
# 5 [‘teacher1‘, ‘teacher2‘, ‘teacher3‘, ‘teacher4‘, ‘teacher5‘, ‘teacher6‘, ‘teacher7‘] [‘苍井空‘, ‘京香‘, ‘波多野结衣‘, ‘小泽玛利亚‘, ‘上原瑞惠‘, ‘樱井莉亚‘, ‘桃谷绘里香‘]
# 6 [‘teacher1‘, ‘teacher2‘, ‘teacher3‘, ‘teacher4‘, ‘teacher5‘, ‘teacher6‘, ‘teacher7‘] [‘苍井空‘, ‘京香‘, ‘波多野结衣‘, ‘小泽玛利亚‘, ‘上原瑞惠‘, ‘樱井莉亚‘, ‘桃谷绘里香‘]

原文地址:https://www.cnblogs.com/JankinYu/p/8457382.html

时间: 2024-07-31 10:39:31

Python学习之路-字典外传的相关文章

Python学习之路-字典dict常用方法

字典特性: dict无序 key唯一,天生去重 创建字典: way1:小心列表坑 1 __author__ = "KuanKuan" 2 d = dict.fromkeys([1, 2, 3], ["name", "age"]) 3 print("字典:", d) 4 5 d[1][0] = "mmph好坑" 6 print("修改后:",d) 7 """

Python学习之路

Python学习之路 目录 Python学习之路[第一篇]:流程控制,用户交互,语法要求,变量,字符,注释,模块导入的使用 Python学习之路[第二篇]:文件,字符串,列表,元组,字典,集合的使用 更新中...

Python学习之路——强力推荐的Python学习资料

资料一:程序媛想事儿(Alexia)总结 Python是一种面向对象.直译式计算机程序设计语言.它的语法简捷和清晰,尽量使用无异义的英语单词,与其它大多数程序设计语言使用大括号不一样,它使用縮进来定义语句块.与Scheme.Ruby.Perl.Tcl等动态语言一样,Python具备垃圾回收功能,能够自动管理内存使用.它经常被当作脚本语言用于处理系统管理任务和网络程序编写,然而它也非常适合完成各种高级任务. Python上手虽然容易,但与其它任何语言一样要学好Python并非一日之功.我的Pyth

Python 学习之路(三)

Python 学习之路(三) 以下所用的是Python 3.6 一.集合部分 集合是一个无序的,不重复的数据集合,主要用来去重,以及关系测试:交集,差集,并集等 1.1 关系操作 1.1.1 列表去重 可以给列表去重,例如: 1 set_demo = [1,2,3,4,5,3,2,1] # 列表 2 set_demo = set(set_demo) # 转换成集合,来去重 3 print(set_demo) 1.1.2 取交集 intersection()方法 可以获得两个集合的交集部分,例如:

Python学习之路(第一周)

走上软件开发之路已经三个年头.我本人是android原生开发出生.期间由于工作的需要以及开发的趋势发展,也走上混合开发的道路,现在主要运用ionic框架进行移动端app的开发.但是未来的互联网发展趋势还是大数据+人工智能.所以现在学习Python就很有必要.这里就不介绍Python语言的优劣了,想具体了解的小伙伴可以自行度娘吧. 好了,直接步入正题. 本博客主要记录自己接下来几个月的Python学习之路,能力有限,期间有什么表达不对的欢迎大家留言区批评指正! Python版本:Python3.5

Python学习之路—2018/6/19

Python学习之路-2018/6/19 1.注册自定义转化器 converts.py class Birthday: regex = '[0-9]{8}' # 匹配规则 def to_python(self, value): # 匹配的字符串返回具体的变量值,传递到对应的视图函数中 return int(value) def to_url(self,value): # 反向解析 return "%04d" % value urls.py from django.urls import

Python学习之路-Day1-Python基础

Python学习之路第一天 学习内容: 1.Python简介 2.安装 3.第一个Python程序 4.变量 5.字符编码 6.用户输入 7.表达式if..else语句 8.表达式for语句 9.break和continue 10.while循环 11.字符串格式化 1.python简介 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承. 最新的TIOB

python 学习笔记 三 字典

字典 Python的高效的key/value哈希表结构叫做"dict", dict的内容可以写成一系列的key:value对并放入{ }中, 相当于: dict = {key1:value1, key2:value2, ...}, 一个空的字典就是俩个大括号{ }. 下面是从一个空字典创建字典以及一些关键点: 数字, 字符串和元组可以作为字典的key, value可以是任何类型(包括字典). ## Can build up a dict by starting with the the

Python学习之路-装饰器&生成器&正则表达式

装饰器 通俗的讲,装饰器就是在不改变源代码基础上,给源代码增加新功能. 不改变函数的源代码.调用方式.返回值等,给函数增加新功能. 经典案例:登录装饰器, def login_decorator(func):     def inner():         if USER_TEMP["status"] == False:             print("\033[31;1m用户未登录,请先登录\033[0m")             login_atm()