主题:  很有意思的一段

cryingfox

职务:普通成员
等级:1
金币:1.0
发贴:172
注册:2000/9/15 18:02:56
#12000/11/4 1:10:34
Can anybody give me any advice on how I can merge 4 list into one ie:

ListA: ["A", "B", "C"]
ListB: ["D", "E", "F"]
ListC: ["G", "H", "I"]
ListD: ["J", "K", "L"]

result= ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"]



Many thanks



cryingfox

职务:普通成员
等级:1
金币:1.0
发贴:172
注册:2000/9/15 18:02:56
#22000/11/4 1:11:00
Doesn't look simple, it but works...
-------------
NewList:=[]
repeat with x:=1 to ListCount(ListA)
NewList[x]:=ListA[x]
end repeat
repeat with x:=1 to ListCount(ListB)
NewList[x+ListCount(ListA)]:=ListB[x]
end repeat
repeat with x:=1 to ListCount(ListC)
NewList[x+ListCount(ListA)+ListCount(ListB)]:=ListC[x]
end repeat
repeat with x:=1 to ListCount(ListD)
NewList[x+ListCount(ListA)+ListCount(ListB)+ListCount(ListC)]:=ListD[x]
end repeat
-------------
Walter



cryingfox

职务:普通成员
等级:1
金币:1.0
发贴:172
注册:2000/9/15 18:02:56
#32000/11/4 1:11:30
How about?

Merge := [ "ListA", "ListB", "ListC", "ListD"]
newList := []

repeat with i := 1 to ListCount( Merge )
repeat with m := 1 to ListCount( Eval(Merge[i]) )
AddLinear( newList, Eval( Merge[i]^"["^m^"]") )
end repeat
end repeat

Andrew Poulos

Walter Khom wrote:

> Doesn't look simple, it but works...
> -------------
> NewList:=[]
> repeat with x:=1 to ListCount(ListA)
> NewList[x]:=ListA[x]
> end repeat
> repeat with x:=1 to ListCount(ListB)
> NewList[x+ListCount(ListA)]:=ListB[x]
> end repeat
> repeat with x:=1 to ListCount(ListC)
> NewList[x+ListCount(ListA)+ListCount(ListB)]:=ListC[x]
> end repeat
> repeat with x:=1 to ListCount(ListD)
> NewList[x+ListCount(ListA)+ListCount(ListB)+ListCount(ListC)]:=ListD[x]
> end repeat



cryingfox

职务:普通成员
等级:1
金币:1.0
发贴:172
注册:2000/9/15 18:02:56
#42000/11/4 1:12:04
Or alternatively Andrew's suggestion could be simplified further:

Merge:=[ListA,ListB,ListC,ListD]
NewList:=[]

repeat with i:=1 to ListCount(Merge)
repeat with m:=1 to ListCount(Merge[i])
AddLinear(NewList,Merge[i,m])
end repeat
end repeat

which avoids the use of Eval.

Using the "Repeat With In" construct simplifies things even further:

NewList:=[]
repeat with i in [ListA,ListB,ListC,ListD]
repeat with m in i
AddLinear(NewList,m)
end repeat
end repeat


Chris Forecast


Andrew Poulos wrote in message
news:3A01DDA7.6A6E1D68@apixel.com...
> How about?
>
> Merge := [ "ListA", "ListB", "ListC", "ListD"]
> newList := []
>
> repeat with i := 1 to ListCount( Merge )
> repeat with m := 1 to ListCount( Eval(Merge[i]) )
> AddLinear( newList, Eval( Merge[i]^"["^m^"]") )
> end repeat
> end repeat










cryingfox

职务:普通成员
等级:1
金币:1.0
发贴:172
注册:2000/9/15 18:02:56
#52000/11/4 1:12:34
Neat solution, simpler than mine, but it should be (so that 'result' is a
new list):

result := List( Replace( "][", "," , String(ListA) ^
String(ListB)^String(ListC)^ String(ListD) ) )

Andrew Poulos

Dave Burnett wrote:

> result := Replace("][", "," , String(ListA) ^ String(ListB)^String(ListC)^
> String(ListD))
>
> Dave
>
> Bert wrote:
>
> > Can anybody give me any advice on how I can merge 4 list into one ie:
> >
> > ListA: ["A", "B", "C"]
> > ListB: ["D", "E", "F"]
> > ListC: ["G", "H", "I"]
> > ListD: ["J", "K", "L"]
> >
> > result= ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"]



Aw天地

职务:普通成员
等级:3
金币:10.0
发贴:836
注册:2000/9/15 23:43:42
#62000/11/4 21:23:57
what you want
多维函数??还是数值的合并
如果是后者为什么这么复杂呢?



cryingfox

职务:普通成员
等级:1
金币:1.0
发贴:172
注册:2000/9/15 18:02:56
#72000/11/5 12:56:42
合并表
推荐的方法是第四种,pretty good!

编辑历史:[这消息被cryingfox编辑过(编辑时间2000-11-05 12:57:33)]
[这消息被cryingfox编辑过(编辑时间2000-11-05 21:52:17)]


Aw天地

职务:普通成员
等级:3
金币:10.0
发贴:836
注册:2000/9/15 23:43:42
#82000/11/5 19:51:43
都能实现
第三种比较简洁充分利用