Check presence of vowels in a string

前端 未结 6 1117
温柔的废话
温柔的废话 2020-12-02 01:54

I need to check whether a vowel is present in a word. If it is, an operation should be carried out on the word say op(word). I want to avoid a for loop because

6条回答
  •  生来不讨喜
    2020-12-02 02:09

    Using set.isdisjoint (This method returns as soon as it found match):

    >>> vowels = set('aeiou') # set('aeiouAEIOU') if you want case-insensitivty
    >>> not vowels.isdisjoint('bcd')
    False
    >>> not vowels.isdisjoint('hello')
    True
    

提交回复
热议问题