Concept
Chopping into Lists (.split())
`.split()` dices a string into a list of words. By default, it splits on whitespace and cleans up consecutive blanks automatically:
python
line = "Python is fast"
print(line.split()) # ['Python', 'is', 'fast']
# 39. Chopping into Lists (.split()) `.split()` dices a string into a list of words. By default, it splits on whitespace and cleans up consecutive blanks automatically: ```python line = "Python is fast" print(line.split()) # ['Python', 'is', 'fast'] ``` Pass a custom separator to parse CSV data: `"a,b,c".split(",")` gives `['a', 'b', 'c']`.
Checkpoint
What does `"red,green,blue".split(",")` return?
Practice
You have `data = "sword,shield,potion"`. Split it by comma `,` and print the resulting list.
01
Tap code blocks below to assemble
Available Blocks