Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.7K Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Creating list of pairs of successive alliterating words?

Posted 2 years ago

I want to create a list of pairs of successive alliterating words, using Select. I have this so far

Select[
 Partition[TextWords@[insert text here], 2, 1],
 StringTake[#, 1] == StringTake[#, 2] &
 ]

but it's not working, I know the StringTake is wrong but I'm not sure how to fix it

POSTED BY: K L
5 Replies
text = "Simply speaking: group word list into subsets with same first 
character, eventually restricted to the CharacterRange, and select 
from the Tally list the subset with count > 1";text = "Simply speaking: 
group word list into subsets  with same first  character,
eventually restricted to the CharacterRange, 
and select   from the Tally list the subset with count > 1";


wordList = TextWords[text];  


allitteralQ[a_ , b_ ] :=  
SameQ @@ ((StringTake[#, 1] & ) /@ (ToLowerCase /@ {a, b}))

Select[Union /@ Gather[wordList, (allitteralQ[#1, #2] &)], (Length[#] > 1 &)]

All in One

Select[Union /@ Gather[ 
TextWords[text], 
Function[{a,b},  SameQ @@ ((StringTake[#, 1] & ) /@ (ToLowerCase /@ {a, b})) ]   ], 
(Length[#] > 1 &)]
POSTED BY: Roland Franzius
Posted 2 years ago

Crossposted here.

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Or, if you are a postfix fan like me

wordList // 
GatherBy[#, StringTake[ToLowerCase@#, 1] &] & // 
Map[Union] //
Select[Length@# > 2 &]
POSTED BY: Rohit Namjoshi
Posted 2 years ago
text = "to to be or or not to be be"

Partition[TextWords@text, 2, 1] // Select[First@# == Last@# &]
(* {{"to", "to"}, {"or", "or"}, {"be", "be"}} *)
POSTED BY: Rohit Namjoshi
Posted 2 years ago

how do you think that could be adjusted for more than pairs of words?

POSTED BY: K L
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard