How does Position work?

*To*: mathgroup at smc.vnet.net*Subject*: [mg85313] How does Position work?*From*: P_ter <peter_van_summeren at yahoo.co.uk>*Date*: Tue, 5 Feb 2008 19:45:44 -0500 (EST)

Hello, JÃ¡nos wrote some time ago a solution which involved lstIn = {2, 3, 4, 4, 2, 1, 1, 5, 4} Flatten[Position[lstIn, #1]] & /@ lstIn This last line gives as result: {{1, 5}, {2}, {3, 4, 9}, {3, 4, 9}, {1, 5}, {6, 7}, {6, 7}, {8}, {3, 4, 9}} One can observe that the last 4 in lstIn has the same result as the first and second 4. Which should be. But! Did Position make a trie (for example) first and then give the results? The document about Position only tells that expressions are searched for in depth-first order. But that does not tell anything about the data structure. I used: lstIn1 = Riffle[ConstantArray[0, 10^4], ConstantArray[1, 10^4]]; One should expect that this would work very fast, but it takes a long time. Does someone know about this? with friendly greetings, P_ter