Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
no vowels function
#6
The point is that replace can only replace 1 word(as your example) or 1 character.
So if word is apple can't write replace('ae', '')
Have to call replace two times.
>>> text = 'apple'
>>> a = text.replace('a', '')
>>> a
'pple'
>>> b = a.replace('e', '')
>>> b
'ppl'   
But using replace is unnecessary and only make the task more difficult than it is.
Here a hint.
>>> text = 'apple'
>>> letters = []
>>> for char in text:     
...     if char not in 'aeiou':
...         letters.append(char)
... 
>>> letters
['p', 'p', 'l']
>>> ''.join(letters)
'ppl' 
Reply


Messages In This Thread
no vowels function - by alex_bgtv - Jan-01-2018, 08:16 AM
RE: no vowels function - by Mekire - Jan-01-2018, 08:29 AM
RE: no vowels function - by squenson - Jan-01-2018, 09:22 AM
RE: no vowels function - by alex_bgtv - Jan-01-2018, 02:09 PM
RE: no vowels function - by squenson - Jan-01-2018, 02:46 PM
RE: no vowels function - by snippsat - Jan-01-2018, 03:08 PM
RE: no vowels function - by alex_bgtv - Jan-01-2018, 08:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  remove vowels in word with conditional ambrozote 12 6,502 May-02-2021, 06:57 PM
Last Post: perfringo
  counting vowels in a string project_science 3 5,883 Dec-30-2020, 06:44 PM
Last Post: buran
  Counting vowels in a string (PyBite #106) Drone4four 4 3,332 Jul-07-2020, 05:29 AM
Last Post: theknowshares
  replace vowels niru 9 23,421 Sep-26-2017, 12:46 PM
Last Post: nilamo
  Vowels and Consonants detector OmarSinno 5 11,200 Sep-21-2017, 02:27 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020