10

You should be using TextWords to segment your data into words. Things like StringCount[data, "far"] will also count "fart". Commonest[TextWords[txt], 10] {"affirm", "calligrapher", "squander", "validly", "autoimmune", "equation", "nematode", "veronica", "crispness", "ashen"} WordCloud[TextWords[txt]] You can use Counts to get the counts of each word as ...


10

StringSplit[#, WhitespaceCharacter... ~~ n : NumberString :> n] & /@ lis {{{"a (b)", "1"}, {"c", "2"}}, {{"d", "3"}, {"e f", "4"}}}


9

Pemutations will do it: letters = {"a", "b", "c"}; Permutations[letters, {3}] {{"a", "b", "c"}, {"a", "c", "b"}, {"b", "a", "c"}, {"b", "c", "a"}, {"c", "a", "b"}, {"c", "b", "a"}} To get all six-letter words: letters = {"a", "b", "c", "d", "e", "f"}; perms = Permutations[letters, {6}]; StringJoin /@ perms {"abcdef", "abcdfe", "abcedf", "abcefd", "...


9

The subscript is interpreted as Times[Subscript[H, 2], O], and Mathematica uses spaces to denote multiplication. You can work around this by using the ZeroWidthTimes option:


9

Some options: Pick[ lis, StringStartsQ[lis[[All, 1]], "a"] ] {{"ab", 2, "c", 3}, {"ac", 5, "f", 6}, {"ad", 9, "c", 10}} Select[lis, StringStartsQ[First[#], "a"] &] {{"ab", 2, "c", 3}, {"ac", 5, "f", 6}, {"ad", 9, "c", 10}} Cases[lis, {_?(StringStartsQ["a"]), ___}] {{"ab", 2, "c", 3}, {"ac", 5, "f", 6}, {"ad", 9, "c", 10}}


8

ClearAll[reArrange] reArrange[s_String] := ## & @@ StringCases[s, StartOfString ~~ w__ ~~ rest__ ~~ EndOfString /; (And @@ DictionaryWordQ /@ {w, ## & @@ StringSplit[rest, "_"]}) :> StringRiffle[{"Food", w, s}, "."]] reArrange /@ l {"Food.ALMOND.ALMONDBEAN", "Food.ALMOND.ALMONDMILK", "Food.ALMOND.ALMONDOLIVE_OIL", "Food....


8

You can try Tally lst = {"aa bb", "cc dd", "aa bb", "aa bb", "cc dd", "ww ss", "ss ss", "kk mm"}; Tally[lst] Edit by m_goldberg As J.M. says in his comment below, Counts will give the same information as an association. Counts[data] <|"aa bb" -> 3, "cc dd" -> 2, "ww ss" -> 1, "ss ss" -> 1, "kk mm" -> 1|> This is equivalent to ...


8

Try this: StringSplit[{s1, s2}, "|"] // Transpose // StringRiffle[#, "|", ""] &


8

This is what you want ? StringJoin[Riffle[Partition[Characters[#], 2], "&&"]] & /@ {"x1x2", "x1", "x1x2x3", "x3", "x4", "x1x2x3x4"} (* Out: {"x1&&x2", "x1", "x1&&x2&&x3", "x3", "x4", "x1&&x2&&x3&&x4"} *)


8

lst = {"x1x2", "x1", "x1x2x3", "x3", "x4", "x1x2x3x4"}; You can use a combination of StringRiffle and StringPartition StringRiffle[StringPartition[#, 2], "&&"] & /@ lst {"x1&&x2", "x1", "x1&&x2&&x3", "x3", "x4", "x1&&x2&&x3&&x4"} Alternatively, you can use StringReplace: StringReplace[lst, ...


7

You can create permutations with all of the letters as strings with: StringJoin /@ Permutations[letters] If you want lists of the individual letters just use: Permutations[letters] Check the documentation of Permutations to learn about permutations with subsets of letters. If you want to use each letter more than once, look at the documentation for ...


7

(Extended comment, not an answer. From the comments to it by OP I do no see the point expanding it further into full blown answer. Thanks to everyone who reacted to it...) Procedure outline Ingest text data. I used Air BnB review data from this site : http://insideairbnb.com/get-the-data.html . Approx. 16000 reviews. (Out of ~500K from Austin, TX and Fort ...


7

Use the the syntax where you specify the order: DateObject[{"06.02.97",{"Day","Month","YearShort"}}] DateObject[{1997, 2, 6, 0, 0, 0.}, "Instant", "Gregorian", -7.]


7

You just got to remove the initial data:image/jpeg;base64,, everything after that is base64 encoded pixel data. data = Import["https://pastebin.com/raw/KHE6A3gR", "Text"]; data = StringReplace[data, "data:image/jpeg;base64," -> ""]; ImportString[data, "Base64"]


6

You could do: StringCases[ "ABCDEFGH", Longest[p__] /; StringMatchQ[p,("D"|"F"|"G")..|("D"|"E"|"H")..|("A"|"B"|"C"|"G")..] ] {"ABC", "DE", "FG", "H"}


6

Short answer: You need to turn off auto styles: CellPrint @ ExpressionCell[ "\!\(\*SubscriptBox[\(H\), \(2\)]\)O (H)", "Input", ShowStringCharacters->False, ShowAutoStyles->False ] The issue is that your string, inside of an "Input" cell is not interpreted as a string, it is interpreted as an expression, and so the default syntax ...


6

strings = {"name", "John", "John Doe", "Doe"}; Pick[strings, BitAnd @@ (IdentityMatrix[Length[strings]] + Boole[Outer[StringFreeQ, strings, strings]]), 1] {"name", "John Doe"} Or equivalently: Pick[strings, MapIndexed[StringFreeQ[Delete[strings, #2], #] &, strings], ConstantArray[True, Length[strings] - 1]] The code below matches only whole ...


6

You actually should work with arrays in this case as the dataset is well-strcutured and quite large. You can import the table in one go as follows. data = Import[ "rawData.txt", "Table", "HeaderLines" -> 19 ]; columns = Transpose[Developer`ToPackedArray[N[data]]]; I extracted only the data columns without column titles so that they can be ...


6

The ` you're seeing is the NumberMarks that Mathematica uses to print real numbers in InputForm and FullForm. You can suppress it with one of the following methods: StringForm["Mean `1`", StandardForm[2.2]] StringForm["Mean `1`", Style[2.2, NumberMarks->False]] Mean 2.2 Mean 2.2 If you're not married to StringForm, you could also use Row: Row[{"...


6

ToString[{"a", "b"}, InputForm] (* "{\"a\", \"b\"}" *) (thanks @kglr for golfing!) If you need to get rid of the space between the strings in the string (as per your specification), then use a StringDelete[" "] operator: ToString[{"a", "b"}, InputForm] // StringDelete[" "] (* "{\"a\",\"b\"}" *)


6

ToExpression is very fast for correct Mathematica syntax input. So the key idea is to create an input string for ToExpression that delivers the expected result for the huge string database in one go: StringData // Extract[{All, 2}] // StringRiffle[#, {"{{", "Nothing},{", "Nothing}}"}] & // ToExpression The odd looking "Nothing}" in ...


6

It is possible to speed up your existing code even without compilation. The idea is to count not all configurations, but rather the topologically different ones. There are 3 topologically distinct possibilities to start a path Corner: 1, 3, 7, 9 Edge: 2, 4, 6, 8 Center: 5 Thus, it is sufficient to count the number of paths starting from 1 (n[1]), ...


6

Create the right structure and then use TeXForm: CenterDot @@ Replace[ FactorInteger[4708352000], {b_, p_Integer} :> HoldForm[b]^p, {1} ] // TeXForm 2^{14}\cdot 5^3\cdot 11^2\cdot 19


5

Pick[lis[[All, 2 ;;]], StringEndsQ[lis[[All, 1]], "bc"]] {{1, 2}, {5, 6}} Also f[{_String?(StringEndsQ["bc"]), x__}] := {x} f[_] := Sequence[] f /@ lis {{1, 2}, {5, 6}}


5

You can wrap Styled objects with ToString[#, StandardForm]& and StringJoin them: StringJoin[ ToString[Style[Subscript[t, 2 g], 48, FontFamily -> "Lucida Handwriting"], StandardForm], ToString[Style[" Element", 32, Red, FontFamily -> "Old English Text MT"], StandardForm]] Alternatively, you can combine elements with different styles using Row: ...


5

updated based on comment feedback One more approach, using LibraryLink. Create a C file called strto.cpp as follows: #include <cstdlib> #include "WolframLibrary.h" EXTERN_C DLLEXPORT int wolfram_strtol(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) { char *string; mint base; mint result; string = ...


5

Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ (HoldForm /@ x / HoldForm /@ y) Also Map[Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &, Inactivate[Divide[x, y]], {-1}] // Activate same picture and style = Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &...


5

The basic process is to turn the symbols into strings, join them together and then make a symbol again. However, if one of the symbols has a definition this won't work if you don't hold the evaluation of the symbols properly. The following function should work even for symbols that have definitions: SetAttributes[symbolNameJoin, HoldAll]; symbolNameJoin[...


5

A slightly different approach is to split the data into lines first, then split each line into fields. Since we know the data begins on line 20, we can do this rawData = Import["rawData.txt", Path -> NotebookDirectory[]]; textLines = StringSplit[rawData, "\n"]; dataIwant = ToExpression[StringSplit /@ textLines[[20 ;;]]]; We used ToExpression to convert ...


5

You can useSequenceReplace: SequenceReplace[lis, {a__} /; And @@ (StringContainsQ[{a}, Alternatives @@ CharacterRange["a", "z"]]) :> StringJoin[a]] % == res True Faster alternatives: SequenceReplace[lis, {a__}/; Nor @@ StringFreeQ[_?LowerCaseQ] @ {a}:> StringJoin[a]] and StringJoin /@ Split[lis, Nor @@ StringFreeQ[_?LowerCaseQ] @ {##}&...


Only top voted, non community-wiki answers of a minimum length are eligible