6 ms·
Luckily, we are writing Python, not Go, so we can use variable names with more than one letter: [word for word in sentence if word not in bannedWords] Sud
by laserlight 2y ago
Luckily, we are writing Python, not Go, so we can use variable names with more than one letter:
[word for word in sentence if word not in bannedWords]
Suddenly, nothing is hard to parse.
- bb88 2y agoI do think people should tend to be more verbose with variable names, in general. And since it's python, use snake case to add faux white space to help the eyes parse the statement.
- archargelod 2y agoI still believe Python comprehensions have confusing structure and in real code I've seen it's 10x worse with 5+ expressions packed in a single line. I much prefer a Nim's style of list comprehensions: let a = collect: for word in wordList: if word notin bannedWords: word let b = collect(for x in list: x) It's still very terse, but, more importanly, it's the same syntax as a regular `for loop`. It has the structure, where in Python complex comprehensions look like a "keyword soup".