1.
b.不可以
c.
tu=("alex",[11,22,{"k1":"v1","k2":["age","name"],"k3":(11,22,33)},44])
tu[1][2]["k2"].append("Seven")
print(tu)
d.
tu[1][2]["k3"] 不可以
2.
dic={"k1":"v1","k2":"v2","k3":[11,22,33]}
a.请循环输出所有的key
for a in dic.keys():
print(a)
b.请循环输出所有的key
for a in dic.values():
print(a)
c.请循环输出所有的key和values
for a in dic.items():
print(a)
d.
dic["k4"]="v4"
print(dic)
e.
dic["k1"]="alex"
print(dic)
f.
dic={"k1":"v1","k2":"v2","k3":{1:[11,22,33]}}
dic["k3"].append(44)
print(dic)
g.
dic["k3"].insert(1,'')
print(dic)
dic.pop('k1')
print(dic)
4.
a='k1:1|k1:2|k2:3|k4:4'
dic={}
lst=a.split('|')
print(lst)
for i in lst:
print(i)
k,v=i.split(":")
dic[k]=int(v)
print(dic)
5. li=[11,56,59,52,98,98,65,69,11,32]
dic={}
list=[]
list2=[]
for a in li :
if a > 66:
list.append(a)
else :
list2.append(a)
print(list)
dic.setdefault("k1",list)
dic.setdefault("k2", list2)
print(dic)
6. lst=[1,2,9,3,"name","电脑"]
goods=[{"name":"电脑","price":""},{"name":"鼠标","price":""},{"name":"键盘","price":""}]
while 1:
xh = input("")
if xh.lower()=='q':
break
elif int(xh) >len(goods) or int(xh) <=0:
print("输入有误")
else:
print(xh+goods[int(xh)-1]["name"]+" "+goods[int(xh)-1]["price"])