# One string in. A list out.
# split() — cutting strings into pieces

# ─────────────────────────────────────────────
# Default split — whitespace
# ─────────────────────────────────────────────

line = "Raven Wolf Ghost Viper Bull"
squad = line.split()
print(squad)
# ['Raven', 'Wolf', 'Ghost', 'Viper', 'Bull']

sentence = "Python is easy to learn"
words = sentence.split()
print(words)
# ['Python', 'is', 'easy', 'to', 'learn']

# extra spaces are ignored with default split
messy = "Red    Horn   Dev"
result = messy.split()
print(result)
# ['Red', 'Horn', 'Dev']

# ─────────────────────────────────────────────
# Split on a separator
# ─────────────────────────────────────────────

data = "Raven,Wolf,Ghost,Viper,Bull"
squad = data.split(",")
print(squad)
# ['Raven', 'Wolf', 'Ghost', 'Viper', 'Bull']

date = "2024-05-15"
parts = date.split("-")
print(parts)
# ['2024', '05', '15']

path = "chapter/lesson/exercise"
segments = path.split("/")
print(segments)
# ['chapter', 'lesson', 'exercise']

# separator is NOT included in the result
# if separator not found — original string returned as single-element list
unknown = "RedHorn".split(",")
print(unknown)
# ['RedHorn']

# ─────────────────────────────────────────────
# maxsplit — limit the number of cuts
# ─────────────────────────────────────────────

line = "PRIORITY URGENT Airstrike confirmed at grid 447"
parts = line.split(" ", 2)
print(parts)
# ['PRIORITY', 'URGENT', 'Airstrike confirmed at grid 447']

# 2 cuts → 3 pieces
# everything after the second cut stays in the last element

log = "ERROR:database:connection refused"
parts = log.split(":", 1)
print(parts)
# ['ERROR', 'database:connection refused']

# ─────────────────────────────────────────────
# split(" ") vs split() — not the same
# ─────────────────────────────────────────────

text = "Red  Horn"           # two spaces between words

print(text.split())          # ['Red', 'Horn']     — extra spaces ignored
print(text.split(" "))       # ['Red', '', 'Horn'] — empty string from double space

# ─────────────────────────────────────────────
# Quick reference
# ─────────────────────────────────────────────

# string.split()             — split on whitespace, ignore extras
# string.split(sep)          — split on separator
# string.split(sep, n)       — max n cuts, n+1 pieces
#
# returns a new list — original string unchanged
# separator not included in result
# split() reverse: join() — covered later
