Cadence Skill 论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4942|回复: 4

[已解决] 请问有没有查找list中特定数据所在的序号的功能或函数?

[复制链接]
发表于 2014-8-27 17:17:47 | 显示全部楼层 |阅读模式
如题,举例如下:
list定义:a={1,3,4,2,6,2,7,5,1,8}
有没有函数不经过遍历,直接得到5的序号为8?

另外想找到小于4的数的序号,例如a里面的1、3、2、2,序号分别为1,2,4,6。有没有这样的函数?同样要求不遍历。
谢谢!
发表于 2014-8-27 19:06:44 | 显示全部楼层
listnindex函数
例子:
  1. (listnindex "dog" '("three" "dog" 'night))
  2. -> 2
复制代码
发表于 2014-9-4 14:09:31 | 显示全部楼层
本帖最后由 XYX365 于 2014-9-18 08:06 编辑
vivienluo 发表于 2014-8-27 19:06
listnindex函数
例子:


應該是list在前面

  1. listnindex('("three" "dog" 'night)  "dog")
  2. => 1
  3. lindex('("three" "dog" 'night)  "dog")
  4. => 2
复制代码

PS. lindex 只有在V16.6版本以上才有的函數
发表于 2014-9-4 21:27:35 | 显示全部楼层
XYX365 发表于 2014-9-4 14:09
應該是list在前面

 楼主| 发表于 2014-9-22 10:02:55 | 显示全部楼层
vivienluo 发表于 2014-8-27 19:06
listnindex函数
例子:

还有几个函数:
1)member 函数
member函数从List的返回第一个元素查找到最后,如果找到返回找到的元素开始直到最后的元素,找不返回nil。
member( 3 '( 2 3 4 3 5 )) => (3 4 3 5)
member( 6 '( 2 3 4 3 5 )) => nil
2)assoc 函数
assoc函数的书写格式为:assoc(g_key l_alist),g_key变量为所查找的关键值,l_alist是为一个由多个List组成的List,格式为:((key1 value1) (key2 value2) (key3 alue3) ...)。
assoc返回查找到的子List。
aList = '(( 1 "one" )( 2 "two" )( 3 "three" ))
assoc( 2 aList ) => ( 2 "two" )
assoc( 5 aList ) => nil
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|网站地图|Cadence Skill 论坛 ( 蜀ICP备13024417号 )

GMT+8, 2024-5-3 18:34 , Processed in 0.131063 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表