I see the point of the question stays in the first elif
:
import random as rnd
vowels="aeiou"
consonants="bcdfghlmnpqrstvz"
alphabet=vowels+consonants
vocabulary={}
index=0
word=""
positions=[]
while index<5:
random_lenght=rnd.randint(2,5)
while len(word)<random_lenght:
random_letter=rnd.randint(0,len(alphabet)-1)
if len(word)==0:
word+=alphabet[random_letter]
elif random_letter != positions[-1] and len(word)>0:
if word[-1] not in vowels:
word+=alphabet[random_letter]
if word[-1] not in consonants:
word+=alphabet[random_letter]
elif random_letter == positions[-1]:
break
if random_letter not in positions:
positions.append(random_letter)
if word not in vocabulary:
vocabulary[index]=word
index+=1
word=""
The result doesn't satisfy me as you suppose:
{0: 'in', 1: 'th', 2: 'cuu', 3: 'th', 4: 'vd'}
Any help would be appreciated.