3

I have a list(lets call it "list") of 5 elements:

['sympathize.', 'sufficient.', 'delightful.', 'contrasted.', 'unsatiable']

I would like to remove vowels ( vowels = ('a', 'e', 'i', 'o', 'u')) from every item of the list and and the final result should be this

The list without vowels:

['sympthz.', 'sffcnt.', 'dlghtfl.', 'cntrstd.', 'nstbl']

Any ideas? Thanks in advance.

My code:

list = ['sympathize.', 'sufficient.', 'delightful.', 'contrasted.','unsatiable']
     vowels = ('a', 'e', 'i', 'o', 'u')
        for x in list.lower():
            if x in vowels:
                words = list.replace(x,"")

Output :

AttributeError: 'list' object has no attribute 'lower'
Costas_
  • 146
  • 1
  • 11
  • well, list has no attribute lower, you can call x.lower() – cmxu Jan 14 '20 at 20:50
  • Don't use the name `list`, as it is a builtin type in Python. – Fred Larson Jan 14 '20 at 20:51
  • words = ['sympathize.', 'sufficient.', 'delightful.', 'contrasted.','unsatiable'] vowels = ('a', 'e', 'i', 'o', 'u') for x in words.lower(): if x in vowels: words = words.replace(x,"") – Costas_ Jan 14 '20 at 20:52
  • I am getting the same error ( for x in words.lower(): AttributeError: 'list' object has no attribute 'lower' ) – Costas_ Jan 14 '20 at 20:53

2 Answers2

3

Try this :

mylist = ['sympathize.', 'sufficient.', 'delightful.', 'contrasted.','unsatiable']
vowels = ['a', 'e', 'i', 'o', 'u']
for i in range(len(mylist)):
    for v in vowels:
        mylist[i] = mylist[i].replace(v,"")
print(mylist)
AmirHmZ
  • 516
  • 3
  • 22
2

Here's one way using str.maketrans:

l = ['sympathize.', 'sufficient.', 'delightful.', 'contrasted.', 'unsatiable']

table = str.maketrans('', '', 'aeiou')

[s.translate(table) for s in l]
# ['sympthz.', 'sffcnt.', 'dlghtfl.', 'cntrstd.', 'nstbl']
yatu
  • 86,083
  • 12
  • 84
  • 139