python字典的键可以用列表吗 |
您所在的位置:网站首页 › python中列表可以作为字典的键吗 › python字典的键可以用列表吗 |
我想用如下词典: 示例:{[8,16]:[[1,2,4,8],8],[16,24]:[[1,2,3,4,8,12],12]} 8和16是将要输入的两个数字,我需要构造一个如上所述的字典。在 使用setdefault,我可以为dictionary中的值创建一个列表,但不能为键创建一个列表 以下是我的代码:#!/usr/bin/env python """ This Program calculates common factors between two Numbers , which is stored on a list and also greatest common factor is also computed. All this is stored in a dictionary Example: { '[n1, n2]': [[Commonfac1(n1,n2), Commonfac2(n1,n2)....Commonfacn(n1,n2)],GreatestCommonFactor] } """ def Factors(number): result = [] for i in range(1, number+1): if (number % i) == 0: result.append(i) return result def Common_Factors(n1, n2): result = [] for element in n1: if ele |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |