Thank you, Rohit! You are right! At the moment, I can modify the code to obtain the correct result, but it will not be as short as the precedent:
Last /@ Flatten[StringPosition["e"]@WordList[], 1] // Histogram
Thank you, Rohit! You are right! At the moment, I can modify the code to obtain the correct result, but it will not be as short as the precedent:
Last /@ Flatten[StringPosition["e"]@WordList[], 1] // Histogram
Another solution
DeleteCases[StringPosition[WordList[], "e"], {}][[All, 1, 1]] // Histogram
Another modification of the code:
Histogram@Flatten@Map[Union, StringPosition[WordList[], "e"], 2]
or
Histogram@Flatten[Union @@@ StringPosition[WordList[], "e"]]
Daily Challenge (Day 8):
Use WL code to restructure the following dataset, so the “ID” is used as the row-identifier instead of the name for each row.
Dataset[
<|"Padmé Amidala" -> <|"ID" -> "19435", "Planet" -> "Naboo"|>,
"Bail Organa" -> <|"ID" -> "11114", "Planet" -> "Alderaan"|>,
"Mon Mothma" -> <|"ID" -> "10712", "Planet" -> "Chandrila"|>|>]
Expected output:
My non-ideal code, that may be checked:
data = Dataset@<|
"Padmé Amidala" -> <|"ID" -> "19435", "Planet" -> "Naboo"|>,
"Bail Organa" -> <|"ID" -> "11114", "Planet" -> "Alderaan"|>,
"Mon Mothma" -> <|"ID" -> "10712", "Planet" -> "Chandrila"|>|>;
name = Keys@Normal[data];
id = Values@Normal[data[All, 1]];
planet = Values@Normal[data[All, 2]];
Dataset@Association@
Array[id[[#]] -> <|"Name" -> name[[#]], "Planet" -> planet[[#]]|> &,
Length@data]
Another possibility:
d = Dataset[Association[
"Padmé Amidala" -> <|"ID" -> "19435", "Planet" -> "Naboo"|>,
"Bail Organa" -> <|"ID" -> "11114", "Planet" -> "Alderaan"|>,
"Mon Mothma" -> <|"ID" -> "10712", "Planet" -> "Chandrila"|>]]
Apply[Association, d[#, "ID"] -> <|"Name" -> #, "Planet" -> d[#, "Planet"]|> & /@ Keys[d]]
Daily Challenge (Day 9):
A pangram is usually understood as a sentence in which every letter of the alphabet is used at least once.
For the letters {“a”, “o”, “l”, “r”, “w”, “f”, “m”}, a pangram would be a word that uses all of the seven letters e.g. “Wolfram”.
Use WL to find a pangram from the letters {“z”, “t”, “c”, “a”, “u”, “h”, “p”}.
If every letter is used exactly once, then the following code solves the problem:
In[1] := Intersection[StringJoin /@ Permutations[{"z", "t", "c", "a", "u", "h", "p"}],
WordList[]]
Out[1] = {"chutzpa"}
or, thanks the Rohit’s idea to use the function Complements:
In[2]:= l = {"z", "t", "c", "a", "u", "h", "p"};
If[Complement[l, Characters@#] == {}, #, Nothing] & /@ WordList[]
Out[2]= {"chutzpa", "chutzpah"}
For at least once
letters = {"z", "t", "c", "a", "u", "h", "p"};
WordList[] // Map[{#, Complement[letters, Characters[#]]} &] //
Select[Last@# == {} &] // Map[First]
(* {"chutzpa", "chutzpah"} *}
Shorter version
WordList[] // Select[Complement[letters, Characters[#]] == {} &]
(* {"chutzpa", "chutzpah"} *)
An identical version with Cases:
In[1]:= l = {"z", "t", "c", "a", "u", "h", "p"};
Cases[x_ /; Complement[l, Characters@x] == {}]@WordList[]
Out[1]= {"chutzpa", "chutzpah"}
@Abrita Chakravarty
I have a query regarding the question.
For the letters, {“a”, “o”, “l”, “r”, “w”, “f”, “m”}, can the pangram apart from containing at least one of each letter from the list also contain some of the remaining letters? Like for example “flamethrower” contains all of the letters from the list but also contains “e” twice, “h” and “t” once which are not part of the list. So is “flamethrower” also regarded as a pangram of this list in addition to “wolfram”?
Some other codes applying operations on sets:
l = {"z", "t", "c", "a", "u", "h", "p"};
Select[ContainsAll[l]@Characters@# &]@WordList[]
or
Select[SubsetQ[Characters@#, l] &]@WordList[]
or
Select[Intersection[Characters@#, l] == Sort@l &]@WordList[]
or
Cases[x_ /; ContainsAll[l]@Characters@x]@WordList[]
or
Cases[x_ /; SubsetQ[Characters@x, l]]@WordList[]
or
Cases[x_ /; Intersection[Characters@x, l] == Sort@l]@WordList[]
Sure, we can apply also the function If[].
@Abrita Chakravarty
First unlike WordList, DictionaryLookup supports patterns. Moreover DictionaryLookup seems to have more words than the WordList (probably a bug).
WordList[]//Length(*39176*)
DictionaryLookup[]//Length(*92518*)
Complement[WordList[],DictionaryLookup[]](*{}*)
Here is my solution:
Clear[pangram];
pangram[characters_List]:=Module[{$characterSet="["<>StringJoin@characters<>"]*"},DictionaryLookup@RegularExpression[StringJoin["(?="<>$characterSet<>#<>")"&/@characters,$characterSet]]];
pangram[{"a","o","l","r","w","f","m"}](*{"wolfram"}*)
pangram[{"z","t","c","a","u","h","p"}](*{"chutzpa","chutzpah"}*)
pangram[{"e","t","l","a","b"}](*{"ablate","ballet","battle","beatable","bleat","eatable","table","tablet"}*)
Its orders of magnitude faster than doing surgery on WordList[] or DictionaryLookup[] alone.
No, a pangram would be a word that uses ONLY the letters from the given set - BUT could use a letter more than once. So for the letters, {“a”, “o”, “l”, “r”, “w”, “f”, “m”}, “flamethrower” would not be considered the pangram.
DictionaryLookup[] contains more words, really:
In[1]:= Complement[DictionaryLookup[], WordList[]] // Length
Out[1]= 53342
Taking the complement other way shows that WordList is a subset of DictionaryLookup so DictionaryLookup is a safe choice.
So, we can construct other codes with DictionaryLookup[], such as for example:
In[1]:= DictionaryLookup[x__ /; SubsetQ[Characters@x, l]]
Out[1]= {"chutzpa", "chutzpah"}
[WSG20] Wolfram Language Basics from EIWL (Days 6, 7, 8, 9)