vowels=["a","e","i","o","u"]
word=["a","ir","the","book"]
for i in word:
if len(i) == 1 and i in vowels:
....
我只是通过这个循环来检测'元音'数组中的'a'并且只有一个空格
喜欢'a'= 1个空格,'ant'= 3个空格。
我想将'a'与数组中的以下单词组合在一起。
如何将'a'与'ir'结合起来使'word'数组成为
word=["air","the","book"]
答案 0 :(得分:1)
您可以使用迭代器构造新列表,只需添加LinearGradientBrush
项,如果当前项为SliderTrackFillPressed
,例如:
SliderTrackFillPointerOver
或者如果你碰巧需要添加多个元音:
<Page.Resources>
<StaticResource x:Key="SliderTrackFillPressed" ResourceKey="MyLinearGradientBrush" />
<StaticResource x:Key="SliderTrackFillPointerOver" ResourceKey="MyLinearGradientBrush" />
<LinearGradientBrush x:Key="MyLinearGradientBrush" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#ff0000" Offset="0.0" />
<GradientStop Color="#ffff00" Offset="0.2" />
<GradientStop Color="#00ff00" Offset="0.4" />
<GradientStop Color="#00ffff" Offset="0.6" />
<GradientStop Color="#0000ff" Offset="0.8" />
<GradientStop Color="#ff00ff" Offset="1.0" />
</LinearGradientBrush>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Slider Grid.Column="1" Orientation="Vertical" Margin="6 0 0 0" Background="{StaticResource MyLinearGradientBrush}">
</Slider>
</Grid>
答案 1 :(得分:0)
>>> vowels = {'a', 'e', 'i', 'o', 'u'} # used set for efficient `in` operation
>>> words = ['a', 'ir', 'the', 'book']
>>> for i in range(len(words) - 2, -1, -1):
... if words[i] in vowels:
... # len(words[i]) == 1 is redundant (all vowels items' length = 1)
... words[i] += words.pop(i + 1) # merge vowel with next word
...
>>> words
['air', 'the', 'book']
注意:向后迭代;否则,只要list.pop
调用,索引就会被破坏。