美文网首页
[080]python第七章-習題(1)

[080]python第七章-習題(1)

作者: 小慷 | 来源:发表于2016-08-26 16:50 被阅读18次

    7-1:字典方法

    用s.update() 或是s|=t都可以把兩字典合併

    7-2:字典的鍵

    鍵值得類型要是可哈希的(hashable),像是用string或是數字可以存取

    但是

    7-3:字典和列表的方法

    (a.)

    a={'b':2,'a':1,'c':3}

    b=sorted(a.keys())

    (b.)

    for i in a:

    print (i,a[i],a)

    (c.)

    用sorted之後,反而只show出排好的鍵,結果值沒有show出來

    7-4

    aList1=[1,2,3,4,5,6]

    aList2=['abc','efg','hi','nm','op','a']

    print dict(zip(aList2,aList1))

    相关文章

      网友评论

          本文标题:[080]python第七章-習題(1)

          本文链接:https://www.haomeiwen.com/subject/vujzsttx.html