其他分享
首页 > 其他分享> > 06-数据类型——字典

06-数据类型——字典

作者:互联网

作业

list1 = [‘name’,‘author’,‘introduce’]
list2 = [‘NORWEGIAN WOOD’,‘Haruki Murakami’,‘balalalala…’]
将list1与list2以键对值的形式呈现

Amy_info = {‘name’:‘amy’,‘addr’:‘hunan’,‘weight’:90} 获取Amy_info的key,value

用户输入随机数个数N,生成N个1到1000内的随机数,去掉相同的,从小到大排序

字节如何转换字符串,字符串如何转换字节

答案

def zuoye1():
    list1 = ['name','author','introduce']
    list2 = ['NORWEGIAN WOOD','Haruki Murakami','balalalala...']
    dict1 = dict(zip(list1,list2))
    print(dict1)
def zuoye2():
    Amy_info = {'name':'amy','addr':'hunan','weight':90}
    for each in Amy_info.items():
        print(each)
def zuoye3():
    import random

    list1 = []
    N = int(input('请输入一个1到1000的整数:'))
    for i in range(0,N):
        x = random.randint(1,1000)
        list1.append(x)
    list1 = list(dict.fromkeys(list1))
    list1.sort()
    print(list1)

bytes转为str—> bytes.decode() 解码
str转为bytes—> str.encode() 编码

标签:info,06,name,list1,数据类型,list2,Amy,bytes,字典
来源: https://blog.csdn.net/zxl1252277960/article/details/111840910