Unexpected TypeError when using list comprehension with generator in Python 3.10
I'm optimizing some code but I'm working on a personal project and I'm not sure how to approach Can someone help me understand I'm trying to figure out I'm working with a `TypeError` when trying to use a generator within a list comprehension in Python 3.10. The goal is to filter out even numbers from a list and then multiply the remaining odd numbers by 2. Here's the code I've written: ```python numbers = range(10) result = [x * 2 for x in (n for n in numbers if n % 2 != 0)] print(result) ``` I expected the output to be `[2, 6, 10, 14]`, but instead, I receive the following behavior: ``` TypeError: 'generator' object is not subscriptable ``` I thought using a generator expression inside the list comprehension would work seamlessly, but it seems like I'm missing something. I've also tried breaking it down into multiple steps: ```python odd_numbers = (n for n in numbers if n % 2 != 0) result = [x * 2 for x in odd_numbers] ``` This version still yields the same `TypeError`. I suspect it has to do with how Python is handling the generator object in this context. Can anyone guide to understand what's going wrong and how to fix this without losing the generator functionality? I want to keep the memory efficiency that comes with using a generator, but I need a working solution as well. What am I doing wrong? This is for a REST API running on Windows 11. I'm coming from a different tech stack and learning Python. Has anyone else encountered this? I'm developing on Ubuntu 22.04 with Python. I'm working with Python in a Docker container on Windows 11. Any feedback is welcome!