python基础-元组列表字典集合原理

1. list和tuple的性能

参考文档

https://blog.csdn.net/run_bomb/article/details/91380795

2. dict和set的原理

参考文档

https://blog.csdn.net/siyue0211/article/details/80560783
https://blog.csdn.net/weixin_40107510/article/details/90637640
https://blog.csdn.net/junjunba2689/article/details/82814166

3. 命名元祖

命名元祖:可以想字典一样通过key去取值

from collections import namedtuple

student_dict = namedtuple('student_info', 'name, age, sex')
students = student_dict('张三', '18', 'female')

print(students)
print(students.name)

>
student_info(name='张三', age='18', sex='female')
张三

4. 推导式

# 列表推导式
l = [i for i in range(10)]

# 字典推导式
d = {i: i*2 for i in range(10)}

print(l)
print(d)
>
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
{0: 0, 1: 2, 2: 4, 3: 6, 4: 8, 5: 10, 6: 12, 7: 14, 8: 16, 9: 18}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值