python字典

a=[1,2,3,4,5]
b=(8,9)
j=0
for i in b:
a.insert(j,i)#j索引位置,i插入的元素
j+=2
print(a)

a=‘abc123cd45’
b=0
for i in a:
if ‘0’<i<‘9’:
b=b*10+int(i)
print(b)
‘’‘展示二维数中所有元素’’’
‘’‘for…while’’’
a=[[7,8,9],[123],[456]]
for i in a:
j=0
while j<len(i):
print(i[j],end=’,’)
j+=1
‘’‘for…for’’’
a=[[1,2,3,],[456],[7,8,9]]
for i in a:
for j in i:
print(j,end=’’)
print()
print()

‘’‘while…while’’’
a=[[1,2,3,],[456],[7,8,9]]
i=0
while i<len(a):
j=a[i]
i+=1
k=0
while k<len(j):
print(j[k],end=’,’)
k+=1
print()
‘’‘while…for’’’
a=[[1,2,3,],[456],[7,8,9]]
i=0
while i<len(a):
j=a[i]
i+=1
k=0
while k<len(j):
print(j[k],end=’,’)
k+=1"""
‘’‘字典’’’
dict1={‘name’:“张三”,‘age’:18,‘adress’:‘北京’}

print(dict1.pop(‘name’))

print(dict1)

del dict1[‘name’]#删除的key

print(dict1)

print(dict1.keys())

print(dict1.values())

print(dict1.items())

‘’‘组合字典元素提取与增加key’’’
a={
‘001’:{‘name’:‘张三’,‘age’:18,‘adress’:‘天津’},
‘002’:{‘name’:‘李四’,‘age’:18,‘adress’:‘北京’},
‘003’:{‘name’:‘王七’,‘age’:18,‘adress’:‘北京’} }

way1

for k,v in a.items():

print(k,end=’’)

for i,j in v.items():

print(i,j,end=’’)

print()

‘’‘way2’’’

for i in a.keys():

b=a[i]

print(i,end=’’)

for j in b.keys():

print(j,b[j],end=’ ')

‘’‘字典末尾增加一个key-value’’’

for i,j in a.items():

if j[‘adress’]==‘北京’:

j[‘房价’]=‘10000’

print(a,end=’ ')

print()

for i in a.keys():
if a[i][‘adress’]==‘北京’:
a[i][‘fangja’]=“10000”
for k,v in a.items():
print(k,v)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值