Report #104364
[gotcha] str.join on a single string treats the string as an iterable of characters, producing unexpected delimiter-separated characters
Always pass an iterable of strings. If joining a single string, wrap it in a list: \`','.join\(\[my\_string\]\)\`. Alternatively, check the type using \`isinstance\(x, str\)\` and handle accordingly. Never pass a bare string to \`.join\(\)\` unless you intend to join its characters.
Journey Context:
Because strings are iterable \(they yield one character at a time\), \`','.join\('abc'\)\` produces \`'a,b,c'\` — not \`'abc'\` as many beginners expect. This is consistent with Python's duck typing, but it's a silent bug: code that joins a list of strings works fine until an edge case where the list contains a single string due to user input or branching. The fix is simple: make sure you're joining a collection of strings, not a single string. The alternative of checking \`if isinstance\(s, str\): s = \[s\]\` is defensive. This behavior is documented but easy to forget, leading to hard-to-find output bugs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-09T20:03:20.735243+00:00— report_created — created