Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将字典转换为元组列表_Python_Pandas_Csv_Attributeerror - Fatal编程技术网

Python 将字典转换为元组列表

Python 将字典转换为元组列表,python,pandas,csv,attributeerror,Python,Pandas,Csv,Attributeerror,我是Python的初学者,我正在尝试解决一个中国邮递员的问题,并跟进 我的步骤是:计算最小重量匹配。 我需要将字典转换为元组列表 下面的代码是我到目前为止的代码 # Compute min weight matching. # Note: max_weight_matching uses the 'weight' attribute by default as the attribute to maximize. odd_matching_dupes = nx.algorithms.max_we

我是Python的初学者,我正在尝试解决一个中国邮递员的问题,并跟进

我的步骤是:计算最小重量匹配。 我需要将字典转换为元组列表

下面的代码是我到目前为止的代码

# Compute min weight matching.
# Note: max_weight_matching uses the 'weight' attribute by default as the attribute to maximize.
odd_matching_dupes = nx.algorithms.max_weight_matching(g_odd_complete, True)

print('Number of edges in matching: {}'.format(len(odd_matching_dupes)))

# Preview of matching with dupes
odd_matching_dupes

# Convert matching to list of deduped tuples
odd_matching = list(pd.unique([tuple(sorted([k, v])) for k, v in 
odd_matching_dupes.items()]))


我为
奇数匹配复制得到的输出是:

{('rep1', 'rep2'),
('rep12', 'rep16'),
('rep17', 'rep13'),
('rep27', 'rep19'),
('rep7', 'rep10'),
('rep8', 'rep5')}

这是我收到的错误消息:

  ---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
<ipython-input-84-7da9b4bbe8a5> in <module>
142 
143 # Convert matching to list of deduped tuples
--> 144 odd_matching = list(pd.unique([tuple(sorted([k, v])) for k, v in 
odd_matching_dupes.items()]))

AttributeError: 'set' object has no attribute 'items'
---------------------------------------------------------------------------
AttributeError回溯(最近一次呼叫上次)
在里面
142
143#将匹配转换为重复数据消除元组列表
-->144奇数匹配=k,v in的列表(pd.unique([tuple(sorted([k,v]))
奇数\u匹配\u重复项。项()))
AttributeError:“set”对象没有属性“items”

奇数匹配重复
是一个
set()
对象
.items()
dict
配合使用您好,欢迎来到StackOverflow。请花些时间阅读帮助页面,特别是命名和的部分。更重要的是,请阅读。您可能还想了解。当您打印
奇数匹配副本时,输出是什么?@sophros我得到的输出是{('rep1','rep2'),('rep12','rep16'),('rep17','rep13'),('rep27','rep19'),('rep7','rep10'),('rep8','rep5'),就像我添加的一样above@Rakesh你好我可以问一下我应该如何更改代码以使其工作吗?
odd\u matching\u dupes
是一个
set()
对象
.items()
dict
配合使用您好,欢迎来到StackOverflow。请花些时间阅读帮助页面,特别是命名和的部分。更重要的是,请阅读。您可能还想了解。当您打印
奇数匹配副本时,输出是什么?@sophros我得到的输出是{('rep1','rep2'),('rep12','rep16'),('rep17','rep13'),('rep27','rep19'),('rep7','rep10'),('rep8','rep5'),就像我添加的一样above@Rakesh你好我可以问一下,我应该如何改变我的代码,使其工作?