- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert a string to a list of words in python?
To convert a string in a list of words, you just need to split it on whitespace. You can use split() from the string class. The default delimiter for this method is whitespace, i.e., when called on a string, it'll split that string at whitespace characters.
>>> "Please split this string".split() ['Please', 'split', 'this', 'string']
Regex can also be used to solve this problem. You can call the re.split() method using the regex '\s+' as delimiter. Note that this method is slower than the above method.
>>> import re >>> re.split('\s+', 'Please split this string') ['Please', 'split', 'this', 'string']
- Python program to convert a list to string
- Convert a list to string in Python program
- Python - Convert list of string to list of list
- How to convert string representation of list to list in Python?
- Convert list of string to list of list in Python
- Python program to convert a list of characters into a string
- Convert a string representation of list into list in Python
- How to convert list to string in Python?
- How to convert a list to string in C#?
- Convert a String to a List of Characters in Java
- Convert a List of String to a comma separated String in Java
- How to convert a list of characters into a string in C#?
- Convert list of numerical string to list of Integers in Python
- Convert string enclosed list to list in Python
- How to convert Python Dictionary to a list?