Skip to main content
added 45 characters in body
Source Link
Rojo
  • 43.1k
  • 7
  • 100
  • 196

StringMatchQ threads its first arguments. Good use of this makes for way faster alternatives to the ones suggested

dic = DictionaryLookup[Repeated[_, 5]]; spatt = "a" ~~ _ ~~ "o" ~~ _ ~~ "t"; Pick[dic, StringMatchQ[dic, spatt]] // AbsoluteTiming Cases[dic, s_ /; StringMatchQ[s, spatt]] // AbsoluteTiming Select[dic, StringMatchQ[#, spatt] &] // AbsoluteTiming 

{0.0050002, {"abort", "about", "adopt", "afoot", "aloft"}}

{0.0480028, {"abort", "about", "adopt", "afoot", "aloft"}}

{0.0500028, {"abort", "about", "adopt", "afoot", "aloft"}}

StringMatchQ threads its first arguments. Good use of this makes for way faster alternatives to the ones suggested

spatt = "a" ~~ _ ~~ "o" ~~ _ ~~ "t"; Pick[dic, StringMatchQ[dic, spatt]] // AbsoluteTiming Cases[dic, s_ /; StringMatchQ[s, spatt]] // AbsoluteTiming Select[dic, StringMatchQ[#, spatt] &] // AbsoluteTiming 

{0.0050002, {"abort", "about", "adopt", "afoot", "aloft"}}

{0.0480028, {"abort", "about", "adopt", "afoot", "aloft"}}

{0.0500028, {"abort", "about", "adopt", "afoot", "aloft"}}

StringMatchQ threads its first arguments. Good use of this makes for way faster alternatives to the ones suggested

dic = DictionaryLookup[Repeated[_, 5]]; spatt = "a" ~~ _ ~~ "o" ~~ _ ~~ "t"; Pick[dic, StringMatchQ[dic, spatt]] // AbsoluteTiming Cases[dic, s_ /; StringMatchQ[s, spatt]] // AbsoluteTiming Select[dic, StringMatchQ[#, spatt] &] // AbsoluteTiming 

{0.0050002, {"abort", "about", "adopt", "afoot", "aloft"}}

{0.0480028, {"abort", "about", "adopt", "afoot", "aloft"}}

{0.0500028, {"abort", "about", "adopt", "afoot", "aloft"}}

Source Link
Rojo
  • 43.1k
  • 7
  • 100
  • 196

StringMatchQ threads its first arguments. Good use of this makes for way faster alternatives to the ones suggested

spatt = "a" ~~ _ ~~ "o" ~~ _ ~~ "t"; Pick[dic, StringMatchQ[dic, spatt]] // AbsoluteTiming Cases[dic, s_ /; StringMatchQ[s, spatt]] // AbsoluteTiming Select[dic, StringMatchQ[#, spatt] &] // AbsoluteTiming 

{0.0050002, {"abort", "about", "adopt", "afoot", "aloft"}}

{0.0480028, {"abort", "about", "adopt", "afoot", "aloft"}}

{0.0500028, {"abort", "about", "adopt", "afoot", "aloft"}}