说出这样的元组列表:
y=[('a', 'b', 'c'),
('a', 'c', 'b'),
('b', 'a', 'c'),
('b', 'c', 'a'),
('c', 'a', 'b'),
('c', 'b', 'a')]
我正在尝试使用 reduce() 功能来制作 y 中每个元素的字符串。''.join(list(x) 让我们说'abc'进行第一次迭代。
z=reduce(lambda x, u=dict(): u.setdefault(''.join(list(x)), []).extend(''.join(list(x))), y)
错误:
AttributeError Traceback (most recent call last)
<ipython-input-102-79858e678e78> in <module>()
----> 1 z=reduce(lambda x, u=dict(): u.setdefault(''.join(list(x)), []).extend(''.join(list(x))), y)
<ipython-input-102-79858e678e78> in <lambda>(x, u)
----> 1 z=reduce(lambda x, u=dict(): u.setdefault(''.join(list(x)), []).extend(''.join(list(x))), y)
AttributeError: 'tuple' object has no attribute 'setdefault'