Find words which contain the most consonants: Difference between revisions

Alternative Python
(Alternative Python)
Line 2,220:
Excluding words which reuse any consonants:
('comprehensible', 9)</pre>
 
===Using generator functions===
<lang python>"""Find words which contain the most consonants. Requires Python >= 3.7."""
import fileinput
import textwrap
 
from itertools import groupby
from operator import itemgetter
 
from typing import Iterable
from typing import List
from typing import Tuple
 
 
VOWELS = frozenset("aeiou")
 
 
def read_words(path: str, encoding="utf-8") -> Iterable[str]:
for line in fileinput.input(path, encoding=encoding):
yield line.strip().lower()
 
 
def filter_words(words: Iterable[str]) -> Iterable[Tuple[str, int]]:
for word in words:
if len(word) <= 10:
continue
 
consonants = [c for c in word if c not in VOWELS]
if len(consonants) != len(set(consonants)):
continue
 
yield word, len(consonants)
 
 
def group_words(words: Iterable[Tuple[str, int]]) -> Iterable[Tuple[int, List[str]]]:
for count, group in groupby(
sorted(words, key=itemgetter(1), reverse=True),
key=itemgetter(1),
):
yield count, [word for word, _ in group]
 
 
def main() -> None:
all_words = read_words("unixdict.txt")
words = filter_words(all_words)
 
for count, word_group in group_words(words):
pretty_words = "\n".join(
textwrap.wrap(" ".join(word_group)),
)
plural = "s" if count > 1 else ""
print(
f"Found {len(word_group)} word{plural} "
f"with {count} unique consonants:\n{pretty_words}\n"
)
 
 
if __name__ == "__main__":
main()
</lang>
 
{{out}}
<pre style="font-size:85%;height:160ex">
Found 1 word with 9 unique consonants:
comprehensible
 
Found 39 words with 8 unique consonants:
administrable anthropology blameworthy bluestocking boustrophedon
bricklaying chemisorption christendom claustrophobia compensatory
comprehensive counterexample demonstrable disciplinary discriminable
geochemistry hypertensive indecipherable indecomposable indiscoverable
lexicography manslaughter misanthropic mockingbird monkeyflower
neuropathology paralinguistic pharmacology pitchblende playwriting
shipbuilding shortcoming springfield stenography stockholder
switchblade switchboard switzerland thunderclap
 
Found 130 words with 7 unique consonants:
acknowledge algorithmic alphanumeric ambidextrous amphibology
anchoritism atmospheric autobiography bakersfield bartholomew
bidirectional bloodstream boardinghouse cartilaginous centrifugal
chamberlain charlemagne clairvoyant combinatorial compensable
complaisant conflagrate conglomerate conquistador consumptive
convertible cosmopolitan counterflow countryside countrywide
declamatory decomposable decomposition deliquescent description
descriptive dilogarithm discernible discriminate disturbance
documentary earthmoving encephalitis endothermic epistemology
everlasting exchangeable exclamatory exclusionary exculpatory
explanatory extemporaneous extravaganza filamentary fluorescent
galvanometer geophysical glycerinate groundskeep herpetology
heterozygous homebuilding honeysuckle hydrogenate hyperboloid
impenetrable imperceivable imperishable imponderable impregnable
improvident improvisation incomparable incompatible incomputable
incredulity indefatigable indigestible indisputable inexhaustible
inextricable inhospitable inscrutable jurisdiction lawbreaking
leatherback leatherneck leavenworth logarithmic loudspeaking
maidservant malnourished marketplace merchandise methodology
misanthrope mitochondria molybdenite nearsighted obfuscatory
oceanography palindromic paradigmatic paramagnetic perfectible
phraseology politicking predicament presidential problematic
proclamation promiscuity providential purchasable pythagorean
quasiparticle quicksilver radiotelephone sedimentary selfadjoint
serendipity sovereignty subjunctive superfluity terminology
valedictorian valedictory verisimilitude vigilantism voluntarism
 
Found 152 words with 6 unique consonants:
aboveground advantageous adventurous aerodynamic anglophobia
anisotropic archipelago automorphic baltimorean beneficiary
borosilicate cabinetmake californium codetermine coextensive
comparative compilation composition confabulate confederate
considerate consolidate counterpoise countervail decisionmake
declamation declaration declarative deemphasize deformation
deliverance demountable denumerable deoxyribose depreciable
deprivation destabilize diagnosable diamagnetic dichotomize
dichotomous disambiguate eigenvector elizabethan encapsulate
enforceable ephemerides epidemiology evolutionary exceptional
exclamation exercisable exhaustible exoskeleton expenditure
experiential exploration fluorescein geometrician hemosiderin
hereinbelow hermeneutic heterogamous heterogeneous heterosexual
hexadecimal hexafluoride homebuilder homogeneity housebroken
icosahedral icosahedron impersonate imprecision improvisate
inadvisable increasable incredulous indivisible indomitable
ineradicable inescapable inestimable inexcusable infelicitous
informatica informative inseparable insuperable ionospheric
justiciable kaleidescope kaleidoscope legerdemain liquefaction
loudspeaker machinelike magisterial maladaptive mantlepiece
manufacture masterpiece meetinghouse meteorology minesweeper
ministerial multifarious musculature observation patrimonial
peasanthood pediatrician persecution pertinacious picturesque
planetarium pleistocene pomegranate predominate prejudicial
prohibition prohibitive prolegomena prosecution provisional
provocation publication quasiperiodic reclamation religiosity
renegotiable residential rooseveltian safekeeping saloonkeeper
serviceable speedometer subrogation sulfonamide superficial
superlative teaspoonful trapezoidal tridiagonal troublesome
vainglorious valediction venturesome vermiculite vocabularian
warehouseman wisenheimer
 
Found 22 words with 5 unique consonants:
acquisition acquisitive acrimonious ceremonious deleterious
diatomaceous egalitarian equilibrate equilibrium equinoctial
expeditious hereinabove homogeneous inequitable injudicious
inoperative inquisitive interviewee leeuwenhoek onomatopoeic
radioactive requisition
 
Found 3 words with 4 unique consonants:
audiovisual bourgeoisie onomatopoeia
</pre>
 
=={{header|R}}==
140

edits