zoukankan      html  css  js  c++  java
  • Python:dictionary

    # Python3.4 Eclipse+PyDev  打开Eclipse,找到Help菜单栏,进入Install New Software…选项。
    # 点击work with:输入框的旁边点击Add…,Name可以随便是什么,我输入的是PyDev,Location是http://pydev.org/updates。点击OK。
    import json
    import os
    import nltk
    import collections
    import heapq
    import operator
    import itertools
    
    
    
    
    sent=["In","the","beginning","God","created"];
    wo=nltk.bigrams(sent);
    for w in wo:
        print(w);
    
    #字典      geovindu 塗聚文
    prices={"ACME":45.23,"APPLE":612.79,"IBM":205.55,"HP":37.20,"FB":10.67};
    min_prices=min(zip(prices.values(),prices.keys()));
    max_prices=max(zip(prices.values(),prices.keys()));
    sort_prices=sorted(zip(prices.values(),prices.keys()));
    name_prices=min(prices,key=lambda k:prices[k]);
    
    max_pricesstr=max(zip(prices.values(),prices.keys()));
    
    print("最小值對應值:"+name_prices);
    
    for mi in min_prices:
        print(mi)
        
    #print(min_prices);
    #print(max_prices);
    #print(sort_prices);
    
    print("排序:");
    for mis in sort_prices:
        print(mis)
    print("最高股票:");
    for mix in max_prices:
        print(mix)
    
    #字典中查相同點
    dirA={
            "geovindu":32,
            "塗聚文":28,
            "江東":12,
            "劉若英":40,
            "english":22
        }
    
    dirB={
           "涂聚文":28,
           "江苏":32,
           "刘若英":40,
           "江東":12,
           "geovindu":32,
           "english":22
        
        }
    dirkey=dirA.keys()&dirB.keys();
    dirvalues=dirA.items()&dirB.items();
    
    print("keys:")
    print(dirkey);
    print("values:")
    print(dirvalues)
    

      

  • 相关阅读:
    PHP用curl发送get post put delete patch请求
    ubuntu中设置php7.0-fpm开机自启动
    对计算机领域中间层的理解
    后端程序猿怎能不会的linux命令
    查看磁盘空间和目录大小的命令
    Http协议详解
    supervisor使用总结
    vmware中扩充磁盘
    HDU 4946 共线凸包
    Codeforces_GYM Flight Boarding Optimization
  • 原文地址:https://www.cnblogs.com/geovindu/p/6378264.html
Copyright © 2011-2022 走看看