def sort_strings_by_vowels(list1):
a = [‘a’,‘e’,‘i’,‘o’,‘u’, “A”, “E”, “I”, “O”, “U”]
dicts={}
s=
for i in list1:
b =0
for j in i:
if j in a:
b += 1
dicts[i]=b
dict_new=sorted(dicts.items(),key=lambda x:x[1],reverse=True)
for z in dict_new:
s.append(z[0])
return s
def sort_strings_by_vowels(words: list) -> list:
len_list = []
result = []
for i in words:
len_list.append([i,len_vowels(i)])
list = sorted(len_list, key=lambda x:x[1],reverse = True)
for i in list:
result.append(i[0])
return result
def len_vowels(str):
list = ['a','e','i','o','u','A','E','I','O','U']
flag = False
len = 0
max = -1
for i in str:
if i in list and flag == False:
flag = True
len = len + 1
elif i in list and flag == True:
len = len + 1
elif i not in list and flag == True:
flag = False
if max < len :
max = len
if max < len :
max = len
return max
str1 = “what a beautiful day today”
str2 = “it’s okay, but very breezy”
list=[str1,str2]
def sort_strings_by_vowels(list):
dict={}
for i in list:
dict.update({(len_aeiou(i)):i}) #字典添加元素进去,不能用赋值
return sorted(dict.items(),key=lambda x:x[1],reverse=True)
def len_aeiou(str):
list_demo=[“a”,“e”,“i”,“o”,“u”,“A”,“E”,“I”,“O”,“U”]
flage=False
len=1
for i in str:
if i in list_demo:
if flage:
len+=1
else:
flage=True
if i not in list_demo :
flage=False
return len
if name == ‘main’:
print(sort_strings_by_vowels(list))
def sort_strings_by_vowels(words: list) -> list:
vowel = "aeiouAEIOU"
words_lis = []
for i in words:
key = 0
key_max = 0
for j in i:
if j in vowel:
key += 1
if key_max < key:
key_max = key
else:
key = 0
words_lis.append((i,key_max))
words_lis.sort(key=lambda x: x[1],reverse=True)
return [i[0] for i in words_lis]
import re
from itertools import groupby
from operator import itemgetter
def sort_strings_by_vowels(words):
vowels_letter = list('aeiouAEIOU')
word_indexs = {}
for word in words:
indexs = [i for letter in vowels_letter for i in range(len(word)) if word[i] == letter]
indexs.sort()
word_indexs[word] = indexs
results_dict = {}
for word,indexs in word_indexs.items():
max_lenth = []
if indexs != []:
for k, g in groupby(enumerate(indexs), lambda x: x[1] - x[0]):
max_lenth.append(len(list(map(itemgetter(1), g))))
results_dict[word] = max(max_lenth)
else:
results_dict[word] = 0
return list(dict(sorted(results_dict.items(),key=lambda x: x[1], reverse=True )).keys())
def sort_strings_by_vowels(words: list) -> list:
dic={}
base_list=['a', 'e', 'i', 'o', 'u']
for word in words:
word_list=[]
word1=word.lower()
for i in range(len(word1)):
if word1[i] in base_list:
if not word_list:
word_list.append([word1[i]])
continue
if word1[i] in base_list and word1[i - 1] in base_list:
word_list[-1].append(word1[i])
if not word_list:
dic[word] = 0
else:
dic[word] = max([len(i) for i in word_list])
return [i[0] for i in sorted(list(dic.items()), key=lambda x: x[1], reverse=True)]
assert sort_strings_by_vowels(["aa", "eee", "oo", "iiii"]) == ["iiii", "eee", "aa", "oo"]
assert sort_strings_by_vowels(["ioue", "ee", "uoiea"]) == ["uoiea", "ioue", "ee"]
assert sort_strings_by_vowels(["AIBRH", "", "YOUNG", "GREEEN"]) == ["GREEEN", "AIBRH", "YOUNG", ""]