split is a Python string method that divides one string wherever a chosen separator appears and returns the resulting pieces as a list. This turns long or awkward text into smaller parts that are easier to inspect and process. section 8.0 section 26.3
Separate email addresses
Given emails = "zebra@zoo.com,red@colors.com,tom.sawyer@book.com,pea@veg.com", write emails_list = emails.split(','). The result is ['zebra@zoo.com', 'red@colors.com', 'tom.sawyer@book.com', 'pea@veg.com']. Each address becomes a separate list element. section 26.3
Use split when a repeated character separates the pieces you need:
- Split comma-separated city names, then sort the resulting list. section 26.5
- Split a cleaned document string on spaces to produce a list of words. section 29.3
- Try quick checks such as splitting alphabet characters by a space, words by spaces, or a sentence on the letter s. section 26.3
Prepare document text
A word-extraction function first replaces newlines with spaces and removes punctuation, then applies text.split(" ") and returns the resulting list. Testing it on a short file first makes errors easier to find before processing a large document. section 29.3
emails_list = emails.split(',')
This short listing shows the central operation: calling split(',') on a string and storing the resulting list. section 26.3










