Python Sage中的奇怪列表输出

Python Sage中的奇怪列表输出,python,list,sage,Python,List,Sage,考虑以下两行代码: 对于t字典,t={1:(1,0,0,0,0,0,0,0),2:(1,1,1,1,1,1,0)},当我尝试执行时:list(t[1])要将元组转换为列表,它会给出输出[(0,1)]。但是当我做列表(1,0,0,0)时,它会给我(应该是)[1,0,0,0]。这里出了什么问题 全文 给我 (1, 0, 0, 0, 0, 0, 0, 0, 0) {1: (1, 0, 0, 0, 0, 0, 0, 0, 0), 2: (1, 1, 1, 1, 1, 1, 1, 1, 0)} [(0,

考虑以下两行代码:

对于
t
字典,
t={1:(1,0,0,0,0,0,0,0),2:(1,1,1,1,1,1,0)}
,当我尝试执行时:
list(t[1])
要将
元组
转换为
列表
,它会给出输出
[(0,1)]
。但是当我做
列表(1,0,0,0)
时,它会给我(应该是)
[1,0,0,0]
。这里出了什么问题

全文 给我

(1, 0, 0, 0, 0, 0, 0, 0, 0)
{1: (1, 0, 0, 0, 0, 0, 0, 0, 0), 2: (1, 1, 1, 1, 1, 1, 1, 1, 0)}
[(0, 1)]

尽管您的
t
看起来像是一个包含整数键和整数值元组的字典,但事实并非如此:

sage: t
{1: (1, 0, 0, 0, 0, 0, 0, 0, 0), 2: (1, 1, 1, 1, 1, 1, 1, 1, 0)}
sage: map(type, t)
[int, int]
sage: map(type, t.values())
[sage.combinat.root_system.ambient_space.AmbientSpace_with_category.element_class,
 sage.combinat.root_system.ambient_space.AmbientSpace_with_category.element_class]
sage: parent(t[1])
Ambient space of the Root system of type ['A', 8]
如果要获得系数的向量,可以使用
.to\u vector()
。例如,我们有

sage: t[1]
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage: type(t[1])
<class 'sage.combinat.root_system.ambient_space.AmbientSpace_with_category.element_class'>
sage: list(t[1])
[(0, 1)]
sage:t[1]
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage:type(t[1])
圣人:名单(t[1])
[(0, 1)]
但是

sage:t[1]。to_vector()
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage:type(t[1]。to_vector())
sage:list(t[1]。to_vector())
[1, 0, 0, 0, 0, 0, 0, 0, 0]

@DSM我添加了我的成绩单,真奇怪它对你有用。我不确定我是否理解你的第二条评论,也就是说,我不确定你的“
打印列表是内置的”列表“
”,谢谢你的更新,它清楚地说明了发生了什么。您的代码与您最初建议的示例非常不同,因为
t[1]
不是一个
tuple
,它是一个
AmbientSpace\u,带有\u category.element\u class
。啊哈!非常感谢@DSM
sage: t[1]
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage: type(t[1])
<class 'sage.combinat.root_system.ambient_space.AmbientSpace_with_category.element_class'>
sage: list(t[1])
[(0, 1)]
sage: t[1].to_vector()
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage: type(t[1].to_vector())
<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
sage: list(t[1].to_vector())
[1, 0, 0, 0, 0, 0, 0, 0, 0]