Created
September 13, 2024 11:47
-
-
Save MrAmbiG/c47b0bf87b696b9324019bf0101500e0 to your computer and use it in GitHub Desktop.
pythong alphanumeric string example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
letters = list(string.ascii_lowercase) | |
vowels = ['a', 'e', 'i', 'o', 'u'] | |
consonants = set(letters).difference(set(vowels)) | |
unwanted = {'x','w','z','f','q'} | |
unwanted2 = {'x','w','z','f','q','h'} | |
cons = consonants.difference(unwanted) | |
cons1 = consonants.difference(unwanted2) | |
def gnames(cons, vowels): | |
''' | |
create a list of 4 letter words which start | |
and end with a vowel, has 2 consonants in the middle | |
''' | |
words = [] | |
for first in vowels: | |
for mid1 in cons: | |
for mid2 in cons: | |
for last in vowels: | |
words.append(first+mid1+mid2+last) | |
return words | |
a=gnames(cons,vowels) | |
print(f"total names are {len(a)}") | |
print(a[150]) | |
print(a.index('amma')) | |
print('-------------------') | |
b=gnames(cons1,vowels) | |
print(f"total names are {len(b)}") | |
print(a[150]) | |
print(a.index('amma')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment