• Register
1 vote
425 views

Problem:

I have a chunk of python code. IN my program, I am trying to remove vowels from a String. However, my program is not running once I hit the run button. Instead of displaying the result, it is returning an error message “ typeerror: can only join an iterable

Why this type of problem occurs in a program and how may I get rid of this? Any idea? I am looking forward to having a solution to it. Find my sample code snippet below

def test(word):
    lower_vowels = ["a","e","i","o","u"]
    upper_vowels = ["A","E","I","O","U"]
    letters = list(word)

    for vowel in lower_vowels:
        try:
            if vowel in word:
                letters = letters.remove(vowel)
        except:
            pass

    for vowel in upper_vowels:
        try:
            if vowel in word:
                letters = letters.remove(vowel)
        except:
            pass

    word = ", "
    word = word.join(letters)
    return word

What seems to be the problem with my code? It might be the .join() function who creates the error.

Thanks for your expert opinion.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes

Solution:

After reviewing your code snippet I’ve got the error from the program. The problem is in the line:

letters = letters.remove(vowel)

Here, the .remove() method never return a value. This line will set the letters to none. So, it will not be iterable in your program. The .remove() function will only remove the first occurrence in the letters.

Now, this should work. Re-write your program and give it another try. If it doesn’t work, please let me know. I’ll have a look again.

Thanks.

13 9 6
94,260 points

Related questions

0 votes
1 answer 37 views
37 views
Problem: I've already looked at this post about iterable python errors:Can only join an iterable&rdquo; python error But that was about the error "cannot assign an iterable". My question is why is python telling me: "list.py", line 6, in <module> reversedlist = ' '.join(toberlist1) TypeError: can only join an iterable I don't know what I am doing wrong! I was following this thread:
asked Feb 14 Mashhoodch 13k points
0 votes
1 answer 27 views
27 views
Problem: How to I Solve this: typeerror: can only assign an iterable HELP! I need help understanding this: typeerror: can only assign an iterable Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 7 Mashhoodch 13k points
0 votes
1 answer 187 views
0 votes
1 answer 371 views
1 vote
1 answer 95 views
95 views
Problem: I am a new student in Python programming. I have made a program that is supposed to take multiple inputs from the user and then print simply. Yeah, I know that sounds pretty easy but I am facing some kind of TypeError from the program. I am attaching the ... am getting is: TypeError: can only concatenate str (not "int") to str What&rsquo;s wrong here? Thanks for your kind help, mate.
asked Jun 29, 2020 adamSw 11.3k points
0 votes
1 answer 3 views
3 views
Problem: Why does this happen: Typeerror: 'nonetype' object is not iterable .
asked Mar 15 Wafa Abu Yousef 6.1k points
2 votes
2 answers 1.6K views
1.6K views
Problem: Hello Kodlogs, I am a new student of Python programming. I am learning the language from YouTube and other voluntary websites and solving basic level problems from them. I&rsquo;ve written a piece of python program that is not working properly and throws back an error ... please point out the issue and help me to fix it? I appreciate your effort and valuable time very much. Thanks a ton.
asked Apr 26, 2020 Gavin 15.3k points
2 votes
1 answer 191 views
191 views
Problem: Hello Kodlogs, I am a new fellow in this forum. I joined the forum because of you people. I think you guys are awesome and pretty much helpful to each other. Well, let me come to the point now. I have a python list in my program. I want to iterate ... (data): for item in data: print(item) I am looking forward to hearing from you. Thanks for your valuable time and kind concern. Thanks.
asked Apr 25, 2020 Gavin 15.3k points
0 votes
1 answer 98 views
98 views
Help me by solving this poblem.
asked Dec 17, 2020 TeamScript 13.5k points
0 votes
1 answer 1.3K views
1.3K views
Problem : I am getting bellow error can only iterate over an array or an instance of java.lang.iterable
asked Nov 1, 2019 peterlaw 6.9k points