Can't find why I keep getting the ValueError when using else statements
Anonymous in /c/coding_help
1194
report
I am making a simple program to load a list of words that appear in a given text, and I am trying to do this using loops. <br><br>The trouble is I keep getting a ValueError and I can't figure out why this is. For now, I just run this code in IDLE, but I don't think that should matter.<br><br>Here is the code:<br><br>```python<br>def load_words():<br> with open("word_list.txt") as file:<br> word_list = file.read().split(", ")<br> return word_list<br><br>def find_common(word_list, text_list):<br> word_list = set(word_list)<br> common_words = []<br><br> for word in word_list:<br> for letter in text_list:<br> if word[0] == letter:<br> common_words.append(word)<br> break<br> return common_words<br><br>def main():<br> word_list = load_words()<br><br> text = input("Please enter your text")<br><br> common_words = find_common(word_list, text)<br> print(common_words)<br><br>if __name__ == "__main__":<br> main()<br>```<br><br>When I run the code it returns the following error:<br><br>```<br>ValueError: not enough values to unpack (expected 2, got 1)<br>```<br><br>I can't seem to figure out why this is. Any advice would be very welcome.<br><br>Edit: Adding the code for `load_words()` and `main()`. I have tried to decrease the code to make it a bit more surmountable.<br><br>Edit 2: The issue is harder than I thought. I will make the example more accurate. Here is the text file:<br><br>```<br>Hello, World!, She sells seashells, Something is afoot here, How now brown cow, Spring's breath, My voice is clamorous, Listen with your heart, quiet and clear. And you will understand at last, How to add to the horse's might, To make your heart stiller and clear and bright.<br>```<br><br>This is what it should produce when given:<br><br>```<br>si<br>```<br><br>```<br>['Something is afoot here', 'Sells'], 'She']<br>si<br>```<br><br>I would like to add more text files, but again it is quiet confusing. I am sorry if the example is not perfect.
Comments (25) 46389 👁️