gh-36606: ruff fix UP027 (list comprehension)
This one is about avoiding creating lists when iterators can do the job.
Scripted using `ruff check --fix --select=UP027 src/sage`
### :memo: Checklist
- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
URL: https://github.com/sagemath/sage/pull/36606
Reported by: Frédéric Chapoton
Reviewer(s): Kwankyu Lee