在Genie中使用字符串列表非常简单。我想知道是否可以在 python 中使用类似于 [-1] 的内容找到最后添加的项目。
以 Genie 的教程为例:
[indent=4]
init
/* test lists */
var l = new list of string
l.add ("Genie")
l.add ("Rocks")
l.add ("The")
l.add ("World")
for s in l
print s
print " "
print l[-1]
目标
我的期望是 l[-1] 位将指向“世界”项目。但是它在执行时给了我错误:
ERROR:arraylist.c:954:gee_array_list_real_get: assertion failed: (index >= 0)
/tmp/geany_run_script_X6D4JY.sh: line 7: 13815 Abortado (imagem do núcleo gravada)/tmp/./test
问题
gee 数组显然只适用于正索引,有没有其他方法可以获取数组中最后添加的项目?