1

Hope you're all well, I wanted to use a dictionary that I found on the internet for a code I have but unfortunately, it was not in the format I wanted it to be in therefore I created this little code to help me put all of the 3000 words in my desired format.

The code worked when I inputted words separated by space however it did not work with the words I got from the website because, on the site, every word was put on a different line like So:

word 1
 
word 2 

Here is my code, I can't get my head around how I can fix it.

wordlist = input ("type the words\n")
wordsSplitted = wordlist.split()
print('"{},"', wordsSplitted )

Error Message:

3
  • 1
    Welcome to Stack Overflow. That error message does not come from Python. You do not have a programming question; you have a "how do I use my computer?" question. To answer it properly, you would need to use superuser.com instead, but you would also have to show them, in enough detail for someone else to reproduce the problem, exactly how you try to run the program. Commented Dec 28, 2021 at 6:52
  • 1
    Are you trying to copy and paste the words from the file into your Python input prompt? If so, there are three options that might work better: (1) in a word processor, replace the line endings with spaces, then paste the long string into your prompt. (2) call input() in a loop and add each word to a list. Stop when the user types some signal (blank line, exclamation point, "done!" or whatever you choose. (3) probably the best: save the word list in a text file on your computer and have your Python program open and read that file directly, converting it to a list of words. Commented Dec 28, 2021 at 7:02
  • Thank you so much Matthias, my problem was quite hard to explain but you understood what I meant, I will follow your suggestions, thanks a lot :) Commented Dec 28, 2021 at 7:04

1 Answer 1

1

Here u can split the words in different lines by a built-in python string function splitlines()

wordlist = """Word 1
word 2"""
wordsSplitted = wordlist.splitlines()
print('"{},"', wordsSplitted)

This should split lines of your string

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.