Python: value => key

  1. list derivatives & dict deconstruction
    ebb = dict(zip('abcde', (11, 22, 11, 33, 22)))
    
    print(ebb)
    
    print([k for k, v in ebb.items() if v == 11])

     

  2. filter
    ebb = dict(zip('abcde', (11, 22, 11, 33, 22)))
    
    print(ebb)
    
    print(dict(filter(lambda item: item[1] == 11, ebb.items())))

     

  3. dict.keys() and dict.values() have the corresponding index
    ebb = dict(zip('abcde', (11, 22, 11, 33, 22)))
    
    print(ebb)
    
    print(tuple(ebb.keys())[tuple(ebb.values()).index(11)])

     

  4. dict derivatives and deconstruction
    ebb = dict(zip('abcde', (11, 22, 11, 33, 22)))
    
    print(ebb)
    
    print({v: k for k, v in ebb.items()}[11])

     

上一篇:System.Data.SQLite.dll 未安装或者版本冲突,按下面步骤操作即可 1、从Nuget卸载所有项目的System.Data.SQLite.dll 和SqlSugar,检查引用中是否还


下一篇:利用nginx解决Nuget无法访问的问题