我很难理解以下几行Python代码。编写代码是为了找到单词“milliways”中包含的元音。
vowels = ['a' , 'e' , 'i' , 'o' , 'u']
word = "milliways"
found = []
for letter in word:
if letter in vowels:
if letter not in found:
found.append(letter)
for vowel in found:
print(vowel)
有人可以帮我理解上面的代码。
答案 0 :(得分:0)
因此,在前三行代码中,我们首先创建一个要搜索的字母(元音)列表,定义一个单词以搜索元音,然后创建一个空数组,我们将在其中存储元音。
接下来,我们遍历我们选择的单词的每个字母,并检查字母是否是元音,而不是已经找到元音的列表,如果符合这些条件,我们将元音添加到“找到”列表。 / p>
在最后两行代码中,我们只需遍历找到的元音列表并将其打印出来,以实际查看我们在单词中找到的元音。
答案 1 :(得分:0)
我已经为您的代码添加了评论,以便您可以看到正在发生的事情
const funcA = (callback, arg1) => {
console.log("Print arg1: " + arg1);
let x = 0;
x = callback(x, arg1);
return x;
}
const funcB = (x, prefix) => {
console.log("Print prefix: " + prefix);
x = x + 1;
return x;
}
/* Exec function funcA */
var x = funcA(x = () => funcB(x = 0 ,"PREFIX_"), "argument1");
console.log("Value of x: " + x);