MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

position of a pattern in a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58138] position of a pattern in a list
  • From: mark <rotree2003 at yahoo.com>
  • Date: Sun, 19 Jun 2005 03:44:09 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

hi
i want to search for the positions
 of the pattern "b" ~~ "c" 
in the list:
lst = {{{"abcd", "cv"}, {"z", "zzbcz"}}
, {{"v"}, {"zbcx"}, {"xc", "bc"}}}
q = StringCases[#, "b" ~~ "c"] & /@ # & /@ lst
Out[]={{{{bc}, {}}, {{}, {bc}}}, {{{}}, {{bc}}, {{}, {bc}}}}
Position[q, {"bc"}]
Out[]={{1, 1, 1}, {1, 2, 2}, {2, 2, 1}, {2, 3, 2}}
this is okay.
but suppose i want to use position directly in the same way 
i have used StringCases:
Position[#, "b" ~~ "c"] & /@ # & /@ lst
Out[]={{{}, {}}, {{}, {}, {{2}}}}
or
Position[lst, "b" ~~ "c"]
Out[]={{2, 3, 2}}
here the Position function could not detect the wanted pattern but only the last explicit "bc", i hope you have ideas about this behaviour.
my second question: can mathematica color  "{" and "}" of the deep nested list in a suitable way so the reader can pursue which one is related to which. if not i think this is a valuable addition in any future versions of mathematica.
thanks



  • Prev by Date: New Line/CR
  • Next by Date: Re: plot command
  • Previous by thread: New Line/CR
  • Next by thread: Re: position of a pattern in a list