今日python
#列表排序操作 sort()升序排序
lst=[1,3,2,4,6,5]
print('before',lst)
lst.sort()
print('after',lst)
#通过指定关键字参数,将列表中的元素进行降序排序
lst.sort(reverse=True) #reverse=true 降序排序 reverse=false 升序排序
print(lst)
lst.sort(reverse=False)
print(lst)
#使用内置函数sorted()对列表进行排序,将产生一个新的列表对象
lst=[1,3,4,2,5,7,6,8,9]
print('before',lst)
new_lst=sorted(lst)
print(lst)
print(new_lst)
#指定关键字函数,实现列表元素的降序排列
desc_list=sorted(lst,reverse=True)
print(desc_list)
'''
sort在原列表基础上进行排序
sorted作为内置函数产生一个新的列表
'''
lst=[i for i in range(1,10)]
print(lst) #[1, 2, 3, 4, 5, 6, 7, 8, 9]
lst=[i*i for i in range(1,10)]
print(lst) #[1, 4, 9, 16, 25, 36, 49, 64, 81]
#[2,4,6,8,10]
lst2=[i*2 for i in range(1,11)]
#字典,以键值对的方式存储数据,字典是一个无序的序列,不可变序列
#字典的创建
scores={'zhang':100,'li':98,'wang':90}
print(scores)
print(type(scores))
student=dict(name='jack',age=20)
print(student)
#空字典
d={}
print(d)
#获取字典的元素
scores={'zhang':100,'li':98,'wang':90}
print(scores['zhang'])
#print(scores['chen']) #KeyError: 'chen'
print(scores.get('zhang'))
#print(scores.get('chen')) #None
print(scores.get('ma',99)) #ma对应value不存在时的默认值,返回99
scores={'zhang':100,'li':98,'wang':90}
print('zhang' in scores) #true
print('zhang' not in scores) #false
del scores['zhang']
print(scores) #删除指定的key-value对
#scores.clear() #请空字典元素
print(scores)
scores['chen']=98 #新增元素
print(scores) #{'li': 98, 'wang': 90, 'chen': 98}
scores['chen']=100 #修改元素
print(scores)
'''
key() 获取字典中所有key
values()获取字典中所有value
items()获取字典中所有key,value对
'''
#字典元素的遍历
scores={'zhang':100,'li':98,'wang':90}
for item in scores:
print(item,scores[item],scores.get(item))
'''
zhang 100 100
li 98 98
wang 90 90'''
#key不允许重复,value可以重复,元素无序,key必须是不可变对象,字典可以根据需要动态的伸缩,会浪费较大的内存,#key不允许重复,value可以重复,元素无序
#key必须是不可变对象,字典可以根据需要动态的伸缩,会浪费较大的内存,是一种使用空间换时间的数据结构
#字典生成式
items=['fruit','book','others']
prices=[90,96,98]
d={items.upper():prices for items,prices in zip(items,prices)}
print(d) #{'FRUIT': 90, 'BOOK': 96, 'OTHERS': 98}
#可变序列 列表,字典
lst=[1,2,3]
print(id(lst))
lst.append(4)
print(id(lst))
#不可变序列,字符串,元组
s='hello'
print(id(s))
s=s+'world'
print(id(s))
print(s)
#元组的创建
t=('python','world',100) #可以省略括号,但是数据类型会变化,元组中只有一个元素时,逗号不能省略
print(t)
print(type(t))
'''('python', 'world', 100)
'''
t1=tuple(('python','world',100))
print(t1)
print(type(t1))
'''('python', 'world', 100)
'''
#元组的遍历
t=('python','world',100)
print(t[0])
print(t[1])
print(t[2])
#print(t[3]) #IndexError: tuple index out of range
#遍历元组
for item in t:
print(item)
单词
amend 修正
plateau 高原
deduce 推断
inevitable 必然的
numerous 众多的
cement 巩固,使团结,水泥
underlying 含蓄的
duplicate 复制
flush 冲洗
sponsor 赞助者
hike 远足
fling 猛投
brevity 简洁的
novelty 新奇
glow 发热
maneuver 演习
vanity 虚荣心
empirical 经验主义的
prosper 蓬勃发展
urgent 紧急的
bulk 大量
torrent 激流
accessory 附件,辅助的
rhetoric 修饰的
corrode 腐蚀
alleviate 减轻
strenuous 费劲的
comet 彗星
versus 对比
pillar 柱
antenna 触角
stitch 缝合
grieve 伤心
susceptible 敏感的
eccentric 古怪的
overhaul 改革
mortal 致死的,普通人
tame 驯服的
reciprocal 互惠的
tentative 暂时的
terminate 结束
documentary 文件 纪录片
frustrate 使心烦
deficiency 缺点
obstacle 障碍
contaminate 弄脏
deploy 部署
rigid 严格的
skeleton 骨骼
auction 拍卖



