Generation of words using the combination of Consonants and Vowels using Python

Python Program

This program accepts two or more words from the user as input, segregates the vowels and consonants in all the words and then generates more words from the combination of vowels and consonants.

For example:

$ python wordgen.py

Enter words separated by spaces: hello world
Consonants: hlllwrd   Vowels: eoo
hollow lower worell woller …

Below is a Python program for the discussed criteria

[code lang="py"]#! /usr/bin/env python
# -*- coding: utf-8 -*-

import enchant
import random

d = enchant.Dict("en_US")
vow = ['a', 'e', 'i', 'o', 'u']
allword = []
string = raw_input("Enter two words to scramble and generate new words: ")

vowels = [letter for letter in string if letter in vow]
#check for vowels in user input and store it.

consonants = [letter for letter in string if letter not in vow]
#check for consonants in user input and store it.

consonants.remove(" ")#remove the space
for i in range(0,100):
ran = random.sample(consonants, 1)
ran1 = random.sample(vowels, 1)
ran2 = random.sample(consonants, 1)
ran3 = random.sample(vowels, 1)
newstring = ran + ran1 + ran2 + ran3
word = "".join(newstring)
if d.check(word) == True:
print word[/code]

Output:


What’s the wait for? Go ahead experimenting with the above program and play with words!!!

Related Posts Plugin for WordPress, Blogger...