173k views
4 votes
How do you split a string of words into a list? Imagine the words are separated by the character ";".

User Shakhawat
by
7.5k points

1 Answer

6 votes

Final answer:

To split a string of words into a list in Python, you can use the split() method with the semicolon as the separator.

Step-by-step explanation:

To split a string of words into a list, you can use the split() method in Python. The split() method splits a string into a list of substrings based on a specified separator. In this case, the separator is the semicolon ';'.

Here's an example:

string_of_words = 'word1;word2;word3;word4'
word_list = string_of_words.split(';')
print(word_list)

This code will output: ['word1', 'word2', 'word3', 'word4']

User Midhun Vijayakumar
by
8.2k points