[Date Index]
[Thread Index]
[Author Index]
Re: List operations
*To*: mathgroup at smc.vnet.net
*Subject*: [mg57992] Re: List operations
*From*: dh <dh at metrohm.ch>
*Date*: Thu, 16 Jun 2005 05:35:48 -0400 (EDT)
*References*: <d8oujp$t95$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Hi Anton,
to get the words:
We extract the structure:
t = Map[0 &, lst, {3}]
then we mark the positions:
t = MapAt[1 &, t, {{2, 2, 2}, {5, 1, 2}}] // Flatten
then we get the position number
t = Position[t, 1] // Flatten
and finally we calculate the distance:
t[[2]] - t[[1]] + 1
all together for words:
t = Map[0 &, lst, {3}]
t = MapAt[1 &, t, {{2, 2, 2}, {5, 1, 2}}] // Flatten
t = Position[t, 1] // Flatten
t[[2]] - t[[1]] + 1
analogously for sentences:
t = Map[0 &, lst, {2}]
t = MapAt[1 &, t, {{2, 2}, {5, 1}}] // Flatten
t = Position[t, 1] // Flatten
t[[2]] - t[[1]] + 1
number of chapters can be calculated directly from the positions:
5-2+1
sincerely, Daniel Huber
hrocht at mail15.com wrote:
> suppose i have a list containing a whole book, the list will contain
> words, sentences, chapters; as an example:
> lst={{{"abc","def"},{"as","red"}},{{"fat","qqq","qqq"},
> {"asd","asd","vbn"}},{{"zz","zz"}},{{"zz","wtt","wtt"}},{{"red","zz"},
> {"sd","ed"},{"er","to"}},{{"ww","ww","dff"},{"as","end"}}}
>
> please check sometimes some servers may insert the false "-" letter
> in the above lst.
>
> here is the book lst contains six chapters, 11 sentences,
> the question is: what are the general methods wich could be used to
> know how many words, and how many sentences and how many chapters
> between an arbitrary two words in the book such as an example:
> between the word number 2 in sentence 2 in chapter 2
> and the word number 2 in sentence 1 in chapter 5
>
> ie:
> wrd1=lst[[2]][[2]][[2]]
> wrd2=lst[[5]][[1]][[2]]
>
> the results will be: if we count the 2 words and their own sentences
> and chapters:
> 9 words, 4 sentences, 4 chapters.
> reards.
> Anton
>
Prev by Date:
**Re: splitting sublists**
Next by Date:
**Mathematica program generating sequence of points stalls for no apparent reason.**
Previous by thread:
**List operations**
Next by thread:
**fitting multiple datasets**
| |