HumDum
HumDum

Reputation: 23

Python - Error while trying to split an input

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:

Upvotes: 1

Views: 202

Answers (1)

Gahan Vig
Gahan Vig

Reputation: 216

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

Upvotes: 1

Related Questions