b = [] i = 0 a = 'programmer' for a in a: if a[i] != 'a' or 'e' or 'y' or 'o' or 'u' or 'i': del a[i] else: b = a[i] i+=1 print(b) - well, I 'll keep it in mind for the future - agre
2 answers
result = [] # хранит результат word = 'programmer' # входное слово vowels = ['a', 'e', 'i', 'o', 'u', 'y'] # набор гласных for ch in word.lower(): # перебираем все буквы входного слова if ch in vowels and ch not in result: # проверяем, есть ли буква с писке главных и не повторяется ли она в результате result.append(ch) # добавляем в результат print(result) >>> ['o', 'a', 'e'] - basically answers) - agre
To find a set of vowel letters of the Latin alphabet present in a given text:
>>> text = "Yam, first, Ä, Ö, Ü, Å, Æ, and я" >>> set("aeiouy").intersection(text.casefold()) {'a', 'i', 'y'} The example also works for ligatures such as fi
If you do not call .casefold() , the result is:
>>> set("aeiouy").intersection(text) {'a'} i , y not found.
Depending on the Unicode normalization, letters with accents can be represented as one or several characters. Lines can fall into a program with different normalization (for example, on a Mac, file names are presented in the form close to NFD. While on Linux, NFC may be more common). This can lead to the fact that the lines that look identical to the human eye, are perceived by the computer as excellent. To accommodate this case, you can use the “canonical caseless matching” defined in section 3.13 of the Unicode standard in D145 :
import unicodedata def NFD(text): return unicodedata.normalize('NFD', text) def canonical_caseless(text): return NFD(NFD(text).casefold()) The result is different from the previous ones:
>>> set("aeiouy").intersection(canonical_caseless(text)) {'a', 'u', 'o', 'y', 'i'} Additionally, the letters 'u' , 'o' (since these letters with accents are represented by two characters in the NFD — one of which is a letter of the Latin alphabet) —It is desirable for a given input, it depends on the specific case under consideration. NFD is used twice in D145 to take into account extremely rare extreme cases such as U + 0345 (you can not use it for Latin vowels).