No computers. Predict outputs and write tiny snippets. Covers everything from Day 16 to Day 19.
split / join / strip / replaces[1:4] / s[::-1] give?append / remove / pop / ins = " Hello World "
print(s.strip().lower().split())
# Write the exact output ↓
split, join, strip, lower, replace — reshape text.
s[i], s[a:b], s[::-1] — reach inside text.
append, remove, pop, in, sort — manage collections.
Plan in steps; the dedupe pattern; tools working together.
Three numbers from one block of text. Each has a one-line trick you already know.
Just the length of the string.
len(text)
Split on whitespace, count the pieces.
len(text.split())
Split on the newline character.
len(text.splitlines())
.splitlines() is just .split()'s cousin — it breaks on line-breaks (\n) instead of spaces.
text = input("Paste your text: ")
chars = len(text)
words = len(text.split())
lines = len(text.splitlines())
print(f"Characters: {chars}")
print(f"Words: {words}")
print(f"Lines: {lines}")
# Bonus — the longest word, using a list + sort:
longest = sorted(text.split(), key=len)[-1]
print(f"Longest word: {longest}")
len, .split(), f-strings, sorted, and slicing [-1] — all in one tidy program.
Read a paragraph and report characters, words, and lines, each on its own labelled line.
Add the longest word, the average word length, and characters excluding spaces.
students/<your-username>/D20_word_counter.py. Full brief in lab/module_2_practice/D20_word_counter/problem.md. PR before 12:00.
dictionaries on Day 21 — and a first taste of Polkadot.